Documentation ¶
Overview ¶
Package util provides logger config and config validation utilities. Basically, it wraps the well-known logging tools zap and lumberjack.
Index ¶
- Variables
- func CreateConsoleCore(consoleConf *ConsoleConfig, level zapcore.Level, encoder zapcore.Encoder) zapcore.Core
- func CreateFileCore(rootpath string, fileConf *FileConfig, level zapcore.Level, ...) (zapcore.Core, error)
- func DefaultTimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder)
- func GetDefault() *zap.Logger
- func NewTextCore(enc zapcore.Encoder, ws zapcore.WriteSyncer, enab zapcore.LevelEnabler) zapcore.Core
- func NewTextEncoder(encoderConfig *zapcore.EncoderConfig, spaced bool, disableErrorVerbose bool) zapcore.Encoder
- func NewTextEncoderByConfig(cfg *Config) zapcore.Encoder
- func ShortCallerEncoder(caller zapcore.EntryCaller, enc zapcore.PrimitiveArrayEncoder)
- type Config
- type ConsoleConfig
- type FileConfig
- type LoggerConfig
Constants ¶
This section is empty.
Variables ¶
var (
// Get retrieves a buffer from the pool, creating one if necessary.
Get = _pool.Get
)
Functions ¶
func CreateConsoleCore ¶
func CreateConsoleCore( consoleConf *ConsoleConfig, level zapcore.Level, encoder zapcore.Encoder, ) zapcore.Core
CreateConsoleCore creates a new zapcore instance whose underlying file descriptor is stdout or stderr.
func CreateFileCore ¶
func CreateFileCore( rootpath string, fileConf *FileConfig, level zapcore.Level, encoder zapcore.Encoder, ) (zapcore.Core, error)
CreateFileCore creates a new zapcore instance whose underlying file descriptor is a lumberjack wrapped regular file.
func DefaultTimeEncoder ¶
func DefaultTimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder)
DefaultTimeEncoder serializes time.Time to a human-readable formatted string
func GetDefault ¶
GetDefault returns the pre-inited default logger. Any code outside `internal/common/log` is not allowed to call this function. Because this function is intentionally designed for the offical logger APIs. They usually wrapps this default console logger as the underlying logger, so that they can output things before the real ones are initialized.
func NewTextCore ¶
func NewTextCore( enc zapcore.Encoder, ws zapcore.WriteSyncer, enab zapcore.LevelEnabler, ) zapcore.Core
NewTextCore creates a Core that writes logs to a WriteSyncer.
func NewTextEncoder ¶
func NewTextEncoderByConfig ¶
NewTextEncoderByConfig creates a fast, low-allocation Text encoder with config. The encoder appropriately escapes all field keys and values.
func ShortCallerEncoder ¶
func ShortCallerEncoder(caller zapcore.EntryCaller, enc zapcore.PrimitiveArrayEncoder)
ShortCallerEncoder serializes a caller in file:line format.
Types ¶
type Config ¶
type Config struct { // Log level. Only logs with a higher level will be printed Level string `yaml:"level"` // Root path for all logs RootPath string `yaml:"root-path"` // DisableErrorVerbose stops annotating logs with the full verbose error message. DisableErrorVerbose bool `yaml:"disable-error-verbose"` // Development puts the logger in development mode, which changes the // behavior of DPanicLevel and takes stacktraces more liberally. Development bool `yaml:"development"` // GlobalLogger confs for all common logger GlobalLogger *LoggerConfig `yaml:"global-logger"` // contains filtered or unexported fields }
Config contains all log related config
func (*Config) IsVerified ¶
IsVerified checks if this config struct was verified or not
type ConsoleConfig ¶
type ConsoleConfig struct { // ConsoleFD is one of `stdout` or `stderr` ConsoleFD string `yaml:"console-fd"` // Highest level you want to output through this console FD LevelMax string `yaml:"level-max"` // Lowest level you want to output through this console FD LevelMin string `yaml:"level-min"` // contains filtered or unexported fields }
ConsoleConfig configs output to stdout or stderr
type FileConfig ¶
type FileConfig struct { // Log Filename, default to stdout FileName string `yaml:"file-name"` // Max size for a single file, in MB, default is 300MB MaxSize int `yaml:"max-size"` // Max days for keeping log files, default is never delete MaxDays int `yaml:"max-days"` // Max number of old log files to retain MaxBackups int `yaml:"max-backups"` // Highest level you want to output through this file LevelMax string `yaml:"level-max"` // Lowest level you want to output through this file LevelMin string `yaml:"level-min"` // contains filtered or unexported fields }
LogFileConfig configs output to a single log file
type LoggerConfig ¶
type LoggerConfig struct { // Configs for logs that output to files Files []*FileConfig `yaml:"file-confs"` // Configs for logs that output to `stderr` or `stdout` Consoles []*ConsoleConfig `yaml:"console-confs"` }
LoggerConfig configs a single logger