logger

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2022 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LEVEL_ERROR   = "error"
	LEVEL_WARNING = "warning"
	LEVEL_INFO    = "info"
	LEVEL_DEBUG   = "debug"
)
View Source
const (
	LUMBERJACK_SCHEME = "lumberjack"
)

Variables

This section is empty.

Functions

func Context

func Context(ctx context.Context) *zap.Logger

Context returns the logger from given context.

func ContextWithFields

func ContextWithFields(ctx context.Context, fields ...zap.Field) context.Context

ContextFields returns a new context appending fields to the contextual logger.

func ContextWithLogger

func ContextWithLogger(ctx context.Context, logger *zap.Logger) context.Context

ContextLogger returns a new context with given logger attached.

func ContextualHandler

func ContextualHandler(opts ...ContextualOption) func(h http.Handler) http.Handler

ContextualHandler returns middleware adding a contextual logger with request IDs.

func Initialize

func Initialize(opts ...LoggerOption) error

Initialize the global logger with given optional configuration parameters. This should be called only once during application bootstrapping.

func RequestIDFrom

func RequestIDFrom(ctx context.Context) (string, error)

RequestIDFrom returns the request ID from context.

func WithRequestID

func WithRequestID(ctx context.Context, id string) context.Context

WithRequestID returns a context with given request ID.

Types

type ContextualOption

type ContextualOption func(http.Handler)

ContextualOption allows optional contextual logger configuration.

func WithBaseLogger

func WithBaseLogger(logger *zap.Logger) ContextualOption

BaseLogger configures the logger from which to derive the contextual logger.

func WithHeaders

func WithHeaders(headers ...string) ContextualOption

WithHeaders configures which HTTP headers to log.

type LoggerOption

type LoggerOption func(*config)

LoggerOption allows configuring the logger.

func WithDevelopment

func WithDevelopment() LoggerOption

WithDevelopment enables more liberal stack traces.

func WithLogFile

func WithLogFile(file string) LoggerOption

WithLogFile configures the the file to store log output.

func WithLogFileCompress

func WithLogFileCompress() LoggerOption

WithLogFileCompress enables compression on the rotated backup files.

func WithLogFileMaxAge

func WithLogFileMaxAge(age int) LoggerOption

WithLogFileMaxAge configures the age in days before a log file is removed.

func WithLogFileMaxBackups

func WithLogFileMaxBackups(backups int) LoggerOption

WithLogFileMaxBackups configures the maximum amount of backup files to maintain.

func WithLogFileMaxSize

func WithLogFileMaxSize(size int) LoggerOption

WithLogFileMaxSize configures the maximum log file size in MB.

func WithLogLevel

func WithLogLevel(level string) LoggerOption

WithLogLevel configures the log level.

Jump to

Keyboard shortcuts

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