logger

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2023 License: MIT Imports: 14 Imported by: 23

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultConfig = Config{
	Format:  FormatYAML,
	Verbose: false,
}

DefaultConfig stores handy default configuration

View Source
var EncoderConfig = zapcore.EncoderConfig{
	TimeKey:        "ts",
	LevelKey:       "level",
	NameKey:        "logger",
	CallerKey:      "caller",
	FunctionKey:    zapcore.OmitKey,
	MessageKey:     "msg",
	StacktraceKey:  "stack",
	LineEnding:     zapcore.DefaultLineEnding,
	EncodeLevel:    zapcore.LowercaseLevelEncoder,
	EncodeTime:     zapcore.RFC3339NanoTimeEncoder,
	EncodeDuration: zapcore.SecondsDurationEncoder,
	EncodeCaller:   zapcore.ShortCallerEncoder,
}

EncoderConfig is the config of log encoder

Functions

func AddFlags added in v0.3.0

func AddFlags(defaultConfig Config, flags *pflag.FlagSet)

AddFlags adds flags defined by logger

func Flags added in v0.3.0

func Flags(defaultConfig Config, name string) *pflag.FlagSet

Flags returns new flag set preconfigured with logger-specific options

func Get

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

Get gets logger from context

func New

func New(config Config) *zap.Logger

New creates new logger

func With

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

With adds new logger to context

func WithLogger

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

WithLogger adds existing logger to context

Types

type Config added in v0.3.0

type Config struct {
	// Format defines the format of log output
	Format Format

	// Verbose turns on verbose logging
	Verbose bool
}

Config stores configuration of the logger

func ConfigureWithCLI added in v0.3.0

func ConfigureWithCLI(defaultConfig Config) Config

ConfigureWithCLI configures logger based on CLI flags

type Format added in v0.3.0

type Format string

Format defines the format of log output

const (
	// FormatConsole causes logs to be printed in console format delivered by zap
	FormatConsole Format = "console"

	// FormatJSON causes logs to be printed in JSON format delivered by zap
	FormatJSON Format = "json"

	// FormatYAML causes logs to be printed in YAML
	FormatYAML Format = "yaml"
)

Jump to

Keyboard shortcuts

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