logger

package
v2.11.0 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ConsoleEncoder zapcore.Encoder = zapcore.NewConsoleEncoder(zapcore.EncoderConfig{
	TimeKey:        "timestamp",
	LevelKey:       "severity",
	NameKey:        "logger",
	CallerKey:      "caller",
	FunctionKey:    zapcore.OmitKey,
	MessageKey:     "message",
	StacktraceKey:  "stacktrace",
	LineEnding:     zapcore.DefaultLineEnding,
	EncodeLevel:    zapcore.LowercaseLevelEncoder,
	EncodeTime:     zapcore.RFC3339TimeEncoder,
	EncodeDuration: zapcore.SecondsDurationEncoder,
	EncodeCaller:   zapcore.ShortCallerEncoder,
})
View Source
var DefaultZapOptions []zap.Option = []zap.Option{
	zap.AddCaller(),

	zap.WrapCore(func(core zapcore.Core) zapcore.Core {
		return zapcore.NewSamplerWithOptions(
			core,
			time.Second,
			100,
			5,
		)
	}),
}
View Source
var JsonEncoder zapcore.Encoder = zapcore.NewJSONEncoder(zapcore.EncoderConfig{
	TimeKey:        "timestamp",
	LevelKey:       "severity",
	NameKey:        "logger",
	CallerKey:      "caller",
	FunctionKey:    zapcore.OmitKey,
	MessageKey:     "message",
	StacktraceKey:  "stacktrace",
	LineEnding:     zapcore.DefaultLineEnding,
	EncodeLevel:    zapcore.LowercaseLevelEncoder,
	EncodeTime:     zapcore.RFC3339TimeEncoder,
	EncodeDuration: zapcore.SecondsDurationEncoder,
	EncodeCaller:   zapcore.ShortCallerEncoder,
})

Functions

func GetLevel

func GetLevel(level Level) zapcore.Level

func NewConsoleLogger

func NewConsoleLogger(config Config, encoder zapcore.Encoder, options ...zap.Option) *zap.Logger

func NewFileLogger

func NewFileLogger(config Config, encoder zapcore.Encoder, options ...zap.Option) (*zap.Logger, error)

func NewLogger

func NewLogger(config Config, encoder zapcore.Encoder, options ...zap.Option) (*zap.Logger, error)

Types

type Config

type Config struct {
	Type       Type
	LogPath    string
	MaxSize    int64
	MaxBackups int
	MaxAge     time.Duration
	Compress   bool
	Level      Level
}

type Level

type Level string
const (
	Debug  Level = "debug"
	Info   Level = "info"
	Warn   Level = "warn"
	Error  Level = "error"
	Dpanic Level = "dpanic"
	Panic  Level = "panic"
	Fatal  Level = "fatal"
)

type Type

type Type string
const (
	Console Type = "console"
	File    Type = "file"
)

Jump to

Keyboard shortcuts

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