Documentation
¶
Index ¶
- Constants
- Variables
- func Debug(ctx context.Context, a ...interface{})
- func Debugf(ctx context.Context, format string, a ...interface{})
- func Debugw(ctx context.Context, keyvals ...interface{})
- func Error(ctx context.Context, a ...interface{})
- func Errorf(ctx context.Context, format string, a ...interface{})
- func Errorw(ctx context.Context, keyvals ...interface{})
- func Fatal(ctx context.Context, a ...interface{})
- func Fatalf(ctx context.Context, format string, a ...interface{})
- func Fatalw(ctx context.Context, keyvals ...interface{})
- func Info(ctx context.Context, a ...interface{})
- func Infof(ctx context.Context, format string, a ...interface{})
- func Infow(ctx context.Context, keyvals ...interface{})
- func Log(ctx context.Context, level Level, keyvals ...interface{})
- func SetLogger(logger Logger)
- func Warn(ctx context.Context, a ...interface{})
- func Warnf(ctx context.Context, format string, a ...interface{})
- func Warnw(ctx context.Context, keyvals ...interface{})
- type Helper
- func (h *Helper) Debug(ctx context.Context, a ...interface{})
- func (h *Helper) Debugf(ctx context.Context, format string, a ...interface{})
- func (h *Helper) Debugw(ctx context.Context, keyvals ...interface{})
- func (h *Helper) Error(ctx context.Context, a ...interface{})
- func (h *Helper) Errorf(ctx context.Context, format string, a ...interface{})
- func (h *Helper) Errorw(ctx context.Context, keyvals ...interface{})
- func (h *Helper) Fatal(ctx context.Context, a ...interface{})
- func (h *Helper) Fatalf(ctx context.Context, format string, a ...interface{})
- func (h *Helper) Fatalw(ctx context.Context, keyvals ...interface{})
- func (h *Helper) Info(ctx context.Context, a ...interface{})
- func (h *Helper) Infof(ctx context.Context, format string, a ...interface{})
- func (h *Helper) Infow(ctx context.Context, keyvals ...interface{})
- func (h *Helper) Warn(ctx context.Context, a ...interface{})
- func (h *Helper) Warnf(ctx context.Context, format string, a ...interface{})
- func (h *Helper) Warnw(ctx context.Context, keyvals ...interface{})
- type Level
- type LogConfig
- type LogConfigOption
- type LogEncoding
- type LogWrapper
- type Logger
- type Option
Constants ¶
View Source
const ( // LevelDebug is logger debug level. LevelDebug = Level(-1) // LevelInfo is logger info level. LevelInfo = Level(0) // LevelWarn is logger warn level. LevelWarn = Level(1) // LevelError is logger error level. LevelError = Level(2) // LevelFatal is logger fatal level. LevelFatal = Level(3) )
View Source
const ( LogEncodingConsole = LogEncoding("console") LogEncodingJSON = LogEncoding("json") )
View Source
const LevelKey = "level"
LevelKey is logger level key.
Variables ¶
View Source
var DefaultLogger = NewStdLogger(log.Writer())
DefaultLogger is default logger.
View Source
var DefaultMessageKey = "msg"
DefaultMessageKey default message key.
Functions ¶
func SetLogger ¶
func SetLogger(logger Logger)
SetLogger should be called before any other log call. And it is NOT THREAD SAFE.
Types ¶
type Helper ¶
type Helper struct {
// contains filtered or unexported fields
}
Helper is a logger helper.
type Level ¶
type Level int8
Level is a logger level.
func ParseLevel ¶
ParseLevel parses a level string into a logger Level value.
type LogConfig ¶
type LogConfig struct {
Level string `json:"level" yaml:"level" env:"DEFAULT_LOG_LEVEL"`
Encoding LogEncoding `json:"encoding" yaml:"encoding" env:"DEFAULT_LOG_ENCODING"`
// 日志存储配置
Filepath string `json:"filepath" yaml:"filepath" env:"DEFAULT_LOG_FILEPATH"`
// MaxSize is the maximum size in megabytes of the log file before it gets
// rotated. It defaults to 100 megabytes.
MaxSize int `json:"maxSize" yaml:"maxSize" env:"DEFAULT_LOG_MAX_SIZE"`
// MaxAge is the maximum number of days to retain old log files based on the
// timestamp encoded in their filename. Note that a day is defined as 24
// hours and may not exactly correspond to calendar days due to daylight
// savings, leap seconds, etc. The default is not to remove old log files
// based on age.
MaxAge int `json:"maxAge" yaml:"maxAge" env:"DEFAULT_LOG_MAX_AGE"`
// MaxBackups is the maximum number of old log files to retain. The default
// is to retain all old log files (though MaxAge may still cause them to get
// deleted.)
MaxBackups int `json:"maxBackups" yaml:"maxBackups" env:"DEFAULT_LOG_MAX_BACKUPS"`
TraceProvider trace.TracerProvider `json:"-"`
}
type LogConfigOption ¶
type LogConfigOption func(*LogConfig)
type LogEncoding ¶
type LogEncoding string
type LogWrapper ¶
type Logger ¶
Logger is a logger interface.
func GetLogger ¶
func GetLogger() Logger
GetLogger returns global logger appliance as logger in current process.
func NewLogger ¶
func NewLogger(opts ...LogConfigOption) (Logger, error)
type Option ¶
type Option func(*Helper)
Option is Helper option.
func WithSprintf ¶
WithSprintf with sprintf
Click to show internal directories.
Click to hide internal directories.