server: go.chromium.org/goma/server/log Index | Examples | Files | Directories

package log

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"}

Index

Examples

Package Files

log.go zap.go

func GRPCUnaryServerInterceptor Uses

func GRPCUnaryServerInterceptor(opts ...grpczap.Option) grpc.UnaryServerInterceptor

GRPCUnaryServerInterceptor returns server interceptor to log grpc calls.

func NewContext Uses

func NewContext(ctx context.Context, logger Logger) context.Context

NewContext returns a new Context that carries logger.

func RegisterTagKey Uses

func RegisterTagKey(key tag.Key)

RegsiterTagKey registers tag key that would be used for log context.

func SetZapLogger Uses

func SetZapLogger(zapLogger *zap.Logger)

SetZapLogger sets zap logger as default logger. Useful for test

log.SetZapLogger(zap.NewExample())

type Logger Uses

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 Uses

func FromContext(ctx context.Context) Logger

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

PathSynopsis
errorreporterPackage errorreporter provides error reporting functionality.

Package log imports 14 packages (graph) and is imported by 30 packages. Updated 2019-11-19. Refresh now. Tools for package owners.