zap

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 20, 2020 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(opts ...Option) log.Logger

New create handler by zap logger.

Example
package main

import (
	"context"

	zlog "gitoa.ru/go-4devs/log/zap"
	"go.uber.org/zap"
)

type ctxKey string

func (c ctxKey) String() string {
	return string(c)
}

const ctxRequestID ctxKey = "requestID"

func getContext() context.Context {
	return context.WithValue(context.TODO(), ctxRequestID, "some requiest id")
}

func main() {
	logger := zlog.New(zlog.WithZap(zap.NewExample()))
	logger.Info(getContext(), "some message in zap")
}
Output:

{"level":"info","msg":"some message in zap"}
Example (WithContext)
package main

import (
	"context"

	"gitoa.ru/go-4devs/log"
	zlog "gitoa.ru/go-4devs/log/zap"
	"go.uber.org/zap"
)

type ctxKey string

func (c ctxKey) String() string {
	return string(c)
}

const ctxRequestID ctxKey = "requestID"

func getContext() context.Context {
	return context.WithValue(context.TODO(), ctxRequestID, "some requiest id")
}

func main() {
	logger := log.With(zlog.New(zlog.WithZap(zap.NewExample())), log.GoVersion("goversion"), log.WithContextValue(ctxRequestID))
	logger.Info(getContext(), "some message in zap")
}
Output:

{"level":"info","msg":"some message in zap","goversion":"go1.15.2","requestID":"some requiest id"}

Types

type Option

type Option func(*logger)

Option configure logger.

func WithLevel

func WithLevel(level log.Level, f func(z *zap.Logger, msg string, fields ...zap.Field)) Option

WithLevel sets level logged message.

func WithZap added in v0.2.0

func WithZap(z *zap.Logger) Option

WithZap sets zap logger.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL