log

package
v0.0.14 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2020 License: BSD-3-Clause Imports: 14 Imported by: 0

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 NewContext added in v0.0.8

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

NewContext returns a new Context that carries logger.

func RegisterTagKey

func RegisterTagKey(key tag.Key)

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

func SetZapLogger

func SetZapLogger(zapLogger *zap.Logger)

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

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

Path Synopsis
Package errorreporter provides error reporting functionality.
Package errorreporter provides error reporting functionality.

Jump to

Keyboard shortcuts

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