log

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2022 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var LevelToSeverity = func(level zerolog.Level) logging.Severity {
	switch level {
	case zerolog.DebugLevel:
		return logging.Debug

	case zerolog.WarnLevel:
		return logging.Warning
	case zerolog.ErrorLevel:
		return logging.Error
	case zerolog.FatalLevel:
		return logging.Alert
	case zerolog.PanicLevel:
		return logging.Emergency
	default:
		return logging.Info
	}
}

LevelToSeverity converts a zerolog level to the stackdriver severity Stackdriver has more levels than zerolog so we skip some severities. By default we set info when no level is provided.

Functions

func Flatten

func Flatten(value interface{}) string

Flatten transforms a struct into a flattened string, like: a.b.c: 'val', c.d: 'val' Pointer values will translate into memory addresses

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!! IMPORTANT SECURITY NOTE !!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Flatten will place ALL keys of the given structure on the resulted string. This means that ANY sensitive data in the flattened structure WILL be exposed!

func MustParseLevel

func MustParseLevel(l string) zerolog.Level

MustParseLevel transforms a string in a zerolog level

func SetupLogger

func SetupLogger(config Config, version string, extraLogWriters ...io.Writer)

SetupLogger sets the global logger by configuring the global zerolog.Log and also the go's log package.

func SetupLoggerWithContext

func SetupLoggerWithContext(ctx context.Context, config Config, version string,
	extraLogWriters ...io.Writer) context.Context

SetupLoggerWithContext returns a context enriched with a logger. The logger is created using SetupLogger, what implies that it will be also available globally.

Types

type Config

type Config struct {
	Level string `default:"info"`
	Human bool   `default:"false"`
	Hook  struct {
		Stackdriver bool `default:"false"`
	}
}

Config is the log configuration struct

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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