logger

package module
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2025 License: MIT Imports: 13 Imported by: 38

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"
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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