logging

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2023 License: Apache-2.0 Imports: 12 Imported by: 84

Documentation

Overview

Package logging sets up and configures standard logging.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Default

func Default() *zap.SugaredLogger

Default creates a default logger. To overwrite log level and mode, set LOG_LEVEL and LOG_MODE.

func FromContext

func FromContext(ctx context.Context) *zap.SugaredLogger

FromContext returns the logger stored in the context. If no such logger exists, a default logger is returned.

func GRPCStreamingInterceptor added in v0.1.2

func GRPCStreamingInterceptor(inLogger *zap.SugaredLogger, projectID string) grpc.StreamClientInterceptor

GRPCStreamingInterceptor returns client-side a gRPC streaming interceptor that populates a logger with trace data in the context.

func GRPCUnaryInterceptor added in v0.1.2

func GRPCUnaryInterceptor(inLogger *zap.SugaredLogger, projectID string) grpc.UnaryServerInterceptor

GRPCUnaryInterceptor returns a client-side gRPC unary interceptor that populates a logger with trace data in the context.

func HTTPInterceptor added in v0.1.2

func HTTPInterceptor(inLogger *zap.SugaredLogger, projectID string) func(http.Handler) http.Handler

HTTPInterceptor returns an HTTP middleware that populates a logger with trace data onto the incoming and outgoing http.Request context.

func NewFromEnv

func NewFromEnv(envPrefix string) *zap.SugaredLogger

NewFromEnv creates a new logger from env vars. Set envPrefix+"LOG_LEVEL" to overwrite log level. Default log level is warning. Set envPrefix+"LOG_MODE" to overwrite log mode. Default log mode is production.

func TestLogger

func TestLogger(tb zaptest.TestingT, opts ...zaptest.LoggerOption) *zap.SugaredLogger

TestLogger returns a logger configured for tests. It will only output log information if specific test fails or is run in verbose mode. See zaptest for more information.

func TestMyThing(t *testing.T) {
	logger := logging.TestLogger(t)
	thing := &MyThing{logger: logger}
}

func WithLogger

func WithLogger(ctx context.Context, logger *zap.SugaredLogger) context.Context

WithLogger creates a new context with the provided logger attached.

Types

This section is empty.

Jump to

Keyboard shortcuts

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