import "go.chromium.org/goma/server/log"
Package log provides logging mechanism for goma servers.
Code:
ctx := context.Background() log.SetZapLogger(zap.NewExample()) logger := log.FromContext(ctx) defer logger.Sync() k, err := tag.NewKey("go.chromium.org/goma/server/log/example") if err != nil { logger.Fatal(err) } log.RegisterTagKey(k) ctx, err = tag.New(ctx, tag.Insert(k, "trace_1")) if err != nil { logger.Fatal(err) } logger = log.FromContext(ctx) logger.Info("info")
Output:
{"level":"info","msg":"info","go.chromium.org/goma/server/log/example":"trace_1"}
func GRPCUnaryServerInterceptor(opts ...grpczap.Option) grpc.UnaryServerInterceptor
GRPCUnaryServerInterceptor returns server interceptor to log grpc calls.
NewContext returns a new Context that carries logger.
RegsiterTagKey registers tag key that would be used for log context.
SetZapLogger sets zap logger as default logger. Useful for test
log.SetZapLogger(zap.NewExample())
type Logger interface { // Debug logs to DEBUG log. Arguments are handled in the manner of fmt.Print. Debug(args ...interface{}) // Debugf logs to DEBUG log. Arguments are handled in the manner of fmt.Printf. Debugf(format string, arg ...interface{}) // Info logs to INFO log. Arguments are handled in the manner of fmt.Print. Info(args ...interface{}) // Infof logs to INFO log. Arguments are handled in the manner of fmt.Printf. Infof(format string, arg ...interface{}) // Warn logs to WARNING log. Arguments are handled in the manner of fmt.Print. Warn(args ...interface{}) // Warnf logs to WARNING log. Arguments are handled in the manner of fmt.Printf. Warnf(format string, arg ...interface{}) // Error logs to ERROR log. Arguments are handled in the manner of fmt.Print. Error(args ...interface{}) // Errorf logs to ERROR log. Arguments are handled in the manner of fmt.Printf. Errorf(format string, arg ...interface{}) // Fatal logs to CRITICAL log. Arguments are handled in te manner of fmt.Print. Fatal(args ...interface{}) // Fatalf logs to CRITICAL log. Arguments are handled in the manner of fmt.Printf. Fatalf(format string, arg ...interface{}) // Sync flushes any buffered log entries. Sync() error }
Logger is logging interface.
FromContext returns logger with context. opencensus's tag registered by RegisterTagKey and trace's span-id and trace-id will be added as context information of the log.
Path | Synopsis |
---|---|
errorreporter | Package errorreporter provides error reporting functionality. |
Package log imports 14 packages (graph) and is imported by 30 packages. Updated 2020-10-27. Refresh now. Tools for package owners.