Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func New ¶
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 ¶
Click to show internal directories.
Click to hide internal directories.