Documentation ¶
Overview ¶
Package log provides logging mechanism for goma servers.
Example ¶
package main import ( "context" "go.opencensus.io/tag" "go.uber.org/zap" "go.chromium.org/goma/server/log" ) func main() { 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"}
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GRPCUnaryServerInterceptor ¶
func GRPCUnaryServerInterceptor(opts ...grpczap.Option) grpc.UnaryServerInterceptor
GRPCUnaryServerInterceptor returns server interceptor to log grpc calls.
func RegisterTagKey ¶
RegsiterTagKey registers tag key that would be used for log context.
func SetZapLogger ¶
SetZapLogger sets zap logger as default logger. Useful for test
log.SetZapLogger(zap.NewExample())
Types ¶
type Logger ¶
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.
func FromContext ¶
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.
Directories ¶
Path | Synopsis |
---|---|
Package errorreporter provides error reporting functionality.
|
Package errorreporter provides error reporting functionality. |
Click to show internal directories.
Click to hide internal directories.