Documentation ¶
Overview ¶
Package log provides the log config.go contains the log config
Package log provides the log
Index ¶
- Constants
- Variables
- func Debug(args ...any)
- func Debugf(format string, args ...any)
- func Error(args ...any)
- func Errorf(format string, args ...any)
- func Fatal(args ...any)
- func Fatalf(format string, args ...any)
- func Info(args ...any)
- func Infof(format string, args ...any)
- func Panicf(format string, args ...any)
- func RegisterLogger(loggerName string, c *Config, opts ...OptionFunc)
- func Sync()
- func Warn(args ...any)
- func Warnf(format string, args ...any)
- type Config
- type FileConfig
- type Logger
- type OptionFunc
Constants ¶
const ( // OutputConsole console output OutputConsole = "console" // OutputFile file output OutputFile = "file" // EncoderTypeConsole log format console encoder EncoderTypeConsole = "console" // EncoderTypeJSON log format json encoder EncoderTypeJSON = "json" )
const DefaultLoggerName = "default"
DefaultLoggerName is the default logger name
Variables ¶
var ( // DefaultConfig default log config DefaultConfig = Config{ Writers: []string{OutputConsole}, Format: EncoderTypeConsole, Level: "info", CallerSkip: 1, } )
var Levels = map[string]zapcore.Level{ "": zapcore.DebugLevel, "debug": zapcore.DebugLevel, "info": zapcore.InfoLevel, "warn": zapcore.WarnLevel, "error": zapcore.ErrorLevel, "fatal": zapcore.FatalLevel, }
Levels zapcore level
Functions ¶
func Debugf ¶
Debugf logs to DEBUG log, Arguments will be formatted with Sprint, Sprintf, or neither.
func Errorf ¶
Errorf logs to ERROR log, Arguments will be formatted with Sprint, Sprintf, or neither.
func Fatalf ¶
Fatalf logs to FATAL log, Arguments will be formatted with Sprint, Sprintf, or neither.
func Panicf ¶
Panicf logs to PANIC log, Arguments will be formatted with Sprint, Sprintf, or neither.
func RegisterLogger ¶
func RegisterLogger(loggerName string, c *Config, opts ...OptionFunc)
RegisterLogger register a logger with name
Types ¶
type Config ¶
type Config struct { LogName string `json:"log_name" yaml:"log_name" mapstructure:"log_name"` // Writers log output(console, file) Writers []string `yaml:"writers" mapstructure:"writers" json:"writers"` // FileConfig log file config, if writers has file, must set file config FileConfig FileConfig `yaml:"file_config" mapstructure:"file_config" json:"file_config"` // Format log format type (console, json) Format string `yaml:"format" mapstructure:"format" json:"format"` // Level log level debug info error... Level string `yaml:"level" mapstructure:"level" json:"level"` // CallerSkip log caller skip CallerSkip int `yaml:"caller_skip" mapstructure:"caller_skip" json:"caller_skip"` }
Config log config
type FileConfig ¶
type FileConfig struct { // Filepath log file path Filepath string `yaml:"filepath" mapstructure:"filepath" json:"filepath"` // MaxAge log file max age, days MaxAge int `yaml:"max_age" mapstructure:"max_age" json:"max_age"` // MaxBackups max backup files MaxBackups int `yaml:"max_backups" mapstructure:"max_backups" json:"max_backups"` // Compress log file is compress Compress bool `yaml:"compress" mapstructure:"compress" json:"compress"` // MaxSize max file size, MB MaxSize int `yaml:"max_size" mapstructure:"max_size" json:"max_size"` }
FileConfig log file config
type Logger ¶
type Logger interface { // Debug logs to DEBUG log Debug(args ...any) // Info logs to INFO log Info(args ...any) // Warn logs to WARN log Warn(args ...any) // Error logs to ERROR log Error(args ...any) // Fatal logs to FATAL log Fatal(args ...any) // Debugln logs to DEBUG log Debugln(args ...any) // Infoln logs to INFO log Infoln(args ...any) // Warnln logs to WARN log Warnln(args ...any) // Errorln logs to ERROR log Errorln(args ...any) // Fatalln logs to FATAL log Fatalln(args ...any) // Debugf logs to DEBUG log, Arguments will be formatted with Sprint, Sprintf, or neither. Debugf(format string, args ...any) // Infof logs to INFO log, Arguments will be formatted with Sprint, Sprintf, or neither. Infof(format string, args ...any) // Warnf logs to WARN log, Arguments will be formatted with Sprint, Sprintf, or neither. Warnf(format string, args ...any) // Errorf logs to ERROR log, Arguments will be formatted with Sprint, Sprintf, or neither. Errorf(format string, args ...any) // Fatalf logs to FATAL log, Arguments will be formatted with Sprint, Sprintf, or neither. Fatalf(format string, args ...any) // Sync calls the zap defaultLogger's Sync method, flushing any buffered log entries. // Applications should take care to call Sync before exiting. Sync() error // WithFields set some business custom data to each log WithFields(fields ...any) Logger }
Logger is the interface that wraps the basic log methods.
func GetLoggerByName ¶
GetLoggerByName get logger by name
func WithFields ¶
WithFields set some business custom data to each log
type OptionFunc ¶
type OptionFunc func(config *Config)
OptionFunc is the option function for LogConfig