Documentation
¶
Overview ¶
Package log is a structured logger for Go, based on https://github.com/uber-go/zap.
Index ¶
- Constants
- Variables
- func AtLevel(level Level, msg string, keysAndValues ...interface{})
- func AtLevelf(level Level, msg string, args ...interface{})
- func AtLevelt(level Level, msg string, fields ...Field)
- func Close() error
- func Configure(opts *Options)
- func Debug(msg string, keysAndValues ...interface{})
- func Debugf(template string, args ...interface{})
- func Debugt(msg string, fields ...Field)
- func DefaultFilenameEncoder() string
- func DefaultTimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder)
- func EncodedFilename() string
- func Error(msg string, keysAndValues ...interface{})
- func Errorf(template string, args ...interface{})
- func Errort(msg string, fields ...Field)
- func Fatal(msg string, keysAndValues ...interface{})
- func Fatalf(template string, args ...interface{})
- func Fatalt(msg string, fields ...Field)
- func Flush() error
- func HourlyFilenameEncoder() string
- func Info(msg string, keysAndValues ...interface{})
- func Infof(template string, args ...interface{})
- func Infot(msg string, fields ...Field)
- func MinutelyFilenameEncoder() string
- func Panic(msg string, keysAndValues ...interface{})
- func Panicf(template string, args ...interface{})
- func Panict(msg string, fields ...Field)
- func Print(args ...interface{})
- func Printf(format string, args ...interface{})
- func Println(args ...interface{})
- func StdLogger(level Level) *log.Logger
- func SugaredL() *zap.SugaredLogger
- func Warn(msg string, keysAndValues ...interface{})
- func Warnf(template string, args ...interface{})
- func Warnt(msg string, fields ...Field)
- type CallerEncoder
- type CheckedEntry
- type DebugLogger
- type Field
- type FilenameEncoder
- type InfoLogger
- type Interface
- type Level
- type LevelEncoder
- type Logger
- func (l *Logger) AtLevel(level Level, msg string, keysAndValues ...interface{})
- func (l *Logger) AtLevelf(level Level, msg string, args ...interface{})
- func (l *Logger) AtLevelt(level Level, msg string, fields ...Field)
- func (l *Logger) Check(lvl Level, msg string) *CheckedEntry
- func (l *Logger) Close() error
- func (l *Logger) Debug(msg string, keysAndValues ...interface{})
- func (l *Logger) DebugLogger() DebugLogger
- func (l *Logger) Debugf(template string, args ...interface{})
- func (l *Logger) Debugt(msg string, fields ...Field)
- func (l *Logger) EncodedFilename() string
- func (l *Logger) Error(msg string, keysAndValues ...interface{})
- func (l *Logger) Errorf(template string, args ...interface{})
- func (l *Logger) Errort(msg string, fields ...Field)
- func (l *Logger) Fatal(msg string, keysAndValues ...interface{})
- func (l *Logger) Fatalf(template string, args ...interface{})
- func (l *Logger) Fatalt(msg string, fields ...Field)
- func (l *Logger) Flush() error
- func (l *Logger) Info(msg string, keysAndValues ...interface{})
- func (l *Logger) InfoLogger() InfoLogger
- func (l *Logger) Infof(template string, args ...interface{})
- func (l *Logger) Infot(msg string, fields ...Field)
- func (l *Logger) Panic(msg string, keysAndValues ...interface{})
- func (l *Logger) Panicf(template string, args ...interface{})
- func (l *Logger) Panict(msg string, fields ...Field)
- func (l *Logger) Print(args ...interface{})
- func (l *Logger) Printf(format string, args ...interface{})
- func (l *Logger) Println(args ...interface{})
- func (l *Logger) Sugared() *zap.SugaredLogger
- func (l *Logger) Warn(msg string, keysAndValues ...interface{})
- func (l *Logger) Warnf(template string, args ...interface{})
- func (l *Logger) Warnt(msg string, fields ...Field)
- func (l *Logger) WithValues(fields ...Field) *Logger
- type Options
- type TimeEncoder
Constants ¶
const (
DefaultCallerSkip = 1
)
Variables ¶
var ( // DebugLevel logs are typically voluminous, and are usually disabled in // production. DebugLevel = zapcore.DebugLevel // InfoLevel is the default logging priority. InfoLevel = zapcore.InfoLevel // WarnLevel logs are more important than Info, but don't need individual // human review. WarnLevel = zapcore.WarnLevel // ErrorLevel logs are high-priority. If an application is running smoothly, // it shouldn't generate any error-level logs. ErrorLevel = zapcore.ErrorLevel // DPanicLevel logs are particularly important errors. In development the // logger panics after writing the message. DPanicLevel = zapcore.DPanicLevel // PanicLevel logs a message, then panics. PanicLevel = zapcore.PanicLevel // FatalLevel logs a message, then calls os.Exit(1). FatalLevel = zapcore.FatalLevel )
Alias for zap log level.
var ( Any = zap.Any Array = zap.Array Binary = zap.Binary Bool = zap.Bool Bools = zap.Bools ByteString = zap.ByteString ByteStrings = zap.ByteStrings Complex64 = zap.Complex64 Complex64s = zap.Complex64s Complex128 = zap.Complex128 Complex128s = zap.Complex128s Duration = zap.Duration Durations = zap.Durations Err = zap.Error Errors = zap.Errors Float32 = zap.Float32 Float32s = zap.Float32s Float64 = zap.Float64 Float64s = zap.Float64s Int = zap.Int Ints = zap.Ints Int8 = zap.Int8 Int8s = zap.Int8s Int16 = zap.Int16 Int16s = zap.Int16s Int32 = zap.Int32 Int32s = zap.Int32s Int64 = zap.Int64 Int64s = zap.Int64s Namespace = zap.Namespace Object = zap.Object Reflect = zap.Reflect Stack = zap.Stack String = zap.String Stringer = zap.Stringer Strings = zap.Strings Time = zap.Time Times = zap.Times Uint = zap.Uint Uints = zap.Uints Uint8 = zap.Uint8 Uint8s = zap.Uint8s Uint16 = zap.Uint16 Uint16s = zap.Uint16s Uint32 = zap.Uint32 Uint32s = zap.Uint32s Uint64 = zap.Uint64 Uint64s = zap.Uint64s Uintptr = zap.Uintptr Uintptrs = zap.Uintptrs )
Alias for zap type functions.
Functions ¶
func Close ¶
func Close() error
Close implements io.Closer, and closes the current logfile of default logger.
func Debug ¶
func Debug(msg string, keysAndValues ...interface{})
Debug logs a message at DebugLevel.
func Debugf ¶
func Debugf(template string, args ...interface{})
Debugf logs a message at DebugLevel.
func DefaultFilenameEncoder ¶
func DefaultFilenameEncoder() string
DefaultFilenameEncoder return <process name>-<date>.log. Rotates daily based on date (YYYYMMDD format).
func DefaultTimeEncoder ¶
func DefaultTimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder)
func EncodedFilename ¶
func EncodedFilename() string
EncodedFilename returns the filename for logging when DisableFile is false.
func Error ¶
func Error(msg string, keysAndValues ...interface{})
Error logs a message at ErrorLevel.
func Errorf ¶
func Errorf(template string, args ...interface{})
Errorf logs a message at ErrorLevel.
func Fatal ¶
func Fatal(msg string, keysAndValues ...interface{})
Fatal logs a message with some additional context, then calls os.Exit.
func Fatalf ¶
func Fatalf(template string, args ...interface{})
Fatalf uses fmt.Sprintf to log a templated message, then calls os.Exit.
func Flush ¶
func Flush() error
Flush calls the underlying Core's Sync method, flushing any buffered log entries. Applications should take care to call Sync before exiting.
func HourlyFilenameEncoder ¶ added in v0.3.0
func HourlyFilenameEncoder() string
HourlyFilenameEncoder returns <process name>-<date>-<hour>.log. Rotates hourly based on date and hour (YYYYMMDD-HH format).
func MinutelyFilenameEncoder ¶ added in v0.3.0
func MinutelyFilenameEncoder() string
MinutelyFilenameEncoder returns <process name>-<date>-<hour>-<minute>.log. Rotates every minute based on date, hour and minute (YYYYMMDD-HHMM format).
func Panic ¶
func Panic(msg string, keysAndValues ...interface{})
Panic logs a message with some additional context, then panics.
func Panicf ¶
func Panicf(template string, args ...interface{})
Panicf uses fmt.Sprintf to log a templated message, then panics.
func Printf ¶ added in v0.1.10
func Printf(format string, args ...interface{})
Printf logs a message at level Print.
func Println ¶ added in v0.1.10
func Println(args ...interface{})
Println logs a message at level Print.
func StdLogger ¶ added in v0.1.6
StdLogger returns logger of standard library which writes to supplied zap logger at the given level.
func SugaredL ¶ added in v0.1.10
func SugaredL() *zap.SugaredLogger
SugaredL returns global sugared logger.
Types ¶
type CallerEncoder ¶ added in v0.1.3
type CallerEncoder = zapcore.CallerEncoder
CallerEncoder is an alias for the zapcore.CallerEncoder.
type CheckedEntry ¶ added in v0.2.2
type CheckedEntry = zapcore.CheckedEntry
CheckedEntry is an alias for the zapcore.CheckedEntry.
func Check ¶ added in v0.2.2
func Check(lvl Level, msg string) *CheckedEntry
Check returns a CheckedEntry if logging a message at the specified level is enabled. It's a completely optional optimization; in high-performance applications, Check can help avoid allocating a slice to hold fields.
type DebugLogger ¶
type FilenameEncoder ¶
type FilenameEncoder func() string
FilenameEncoder log filename encoder, return the full name of the log file.
type InfoLogger ¶
type InfoLogger interface {
DebugLogger
Infot(msg string, fields ...Field)
Infof(template string, args ...interface{})
Info(msg string, keysAndValues ...interface{})
}
type Interface ¶
type Interface interface {
InfoLogger
Warnt(msg string, fields ...Field)
Warnf(template string, args ...interface{})
Warn(msg string, keysAndValues ...interface{})
Errort(msg string, fields ...Field)
Errorf(template string, args ...interface{})
Error(msg string, keysAndValues ...interface{})
Panict(msg string, fields ...Field)
Panicf(template string, args ...interface{})
Panic(msg string, keysAndValues ...interface{})
Fatalt(msg string, fields ...Field)
Fatalf(template string, args ...interface{})
Fatal(msg string, keysAndValues ...interface{})
AtLevelt(level Level, msg string, fields ...Field)
AtLevelf(level Level, template string, args ...interface{})
AtLevel(level Level, msg string, keysAndValues ...interface{})
// WithValues creates a child logger and adds some Field of
// context to this logger.
WithValues(fields ...Field) *Logger
// Flush calls the underlying Core's Sync method, flushing any buffered
// log entries. Applications should take care to call Sync before exiting.
Flush() error
// Close implements io.Closer, and closes the current logfile.
Close() error
}
type LevelEncoder ¶ added in v0.1.3
type LevelEncoder = zapcore.LevelEncoder
LevelEncoder is an alias for the zapcore.LevelEncoder.
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
func WithValues ¶
WithValues creates a child logger and adds some Field of context to this logger.
func (*Logger) Check ¶ added in v0.2.2
func (l *Logger) Check(lvl Level, msg string) *CheckedEntry
Check returns a CheckedEntry if logging a message at the specified level is enabled. It's a completely optional optimization; in high-performance applications, Check can help avoid allocating a slice to hold fields.
func (*Logger) Close ¶
Close implements io.Closer, and closes the current logfile of default logger.
func (*Logger) DebugLogger ¶
func (l *Logger) DebugLogger() DebugLogger
func (*Logger) EncodedFilename ¶ added in v0.1.9
func (*Logger) Flush ¶
Flush calls the underlying Core's Sync method, flushing any buffered log entries. Applications should take care to call Sync before exiting.
func (*Logger) InfoLogger ¶
func (l *Logger) InfoLogger() InfoLogger
func (*Logger) Print ¶ added in v0.1.10
func (l *Logger) Print(args ...interface{})
Print logs a message at level Print.
func (*Logger) Println ¶ added in v0.1.10
func (l *Logger) Println(args ...interface{})
Println logs a message at level Print.
func (*Logger) Sugared ¶ added in v0.1.10
func (l *Logger) Sugared() *zap.SugaredLogger
Sugared returns sugared logger. SugaredLogger wraps the Logger to provide a more ergonomic, but slightly slower, API. Sugaring a Logger is quite inexpensive, so it's reasonable for a single application to use both Loggers and SugaredLoggers, converting between them on the boundaries of performance-sensitive code.
func (*Logger) WithValues ¶
WithValues creates a child logger and adds some Field of context to this logger.
type Options ¶
type Options struct {
// DisableConsole whether to log to console
DisableConsole bool `json:"disable-console" mapstructure:"disable-console"`
// DisableConsoleColor force disabling colors.
DisableConsoleColor bool `json:"disable-console-color" mapstructure:"disable-console-color"`
// DisableConsoleTime whether to add a time
DisableConsoleTime bool `json:"disable-console-time" mapstructure:"disable-console-time"`
// DisableConsoleLevel whether to add a level
DisableConsoleLevel bool `json:"disable-console-level" mapstructure:"disable-console-level"`
// DisableConsoleCaller whether to log caller info
DisableConsoleCaller bool `json:"disable-console-caller" mapstructure:"disable-console-caller"`
// DisableFile whether to log to file
DisableFile bool `json:"disable-file" mapstructure:"disable-file"`
// DisableFileJson whether to enable json format for log file
//nolint:revive
DisableFileJson bool `json:"disable-file-json" mapstructure:"disable-file-json"`
// DisableFileTime whether to add a time
DisableFileTime bool `json:"disable-file-time" mapstructure:"disable-file-time"`
// DisableFileCaller whether to log caller info
DisableFileCaller bool `json:"disable-file-caller" mapstructure:"disable-file-caller"`
// DisableRotate whether to enable log file rotate
DisableRotate bool `json:"disable-rotate" mapstructure:"disable-rotate"`
// MaxSize the max size in MB of the logfile before it's rolled
MaxSize int `json:"max-size" mapstructure:"max-size"`
// MaxBackups the max number of rolled files to keep
MaxBackups int `json:"max-backups" mapstructure:"max-backups"`
// MaxAge the max age in days to keep a logfile
MaxAge int `json:"max-age" mapstructure:"max-age"`
// CallerSkip increases the number of callers skipped by caller annotation
CallerSkip int `json:"caller-skip" mapstructure:"caller-skip"`
// ConsoleLevel sets the standard logger level
ConsoleLevel string `json:"console-level" mapstructure:"console-level"`
// FileLevel sets the file logger level.
FileLevel string `json:"file-level" mapstructure:"file-level"`
// Output directory for logging when DisableFile is false
Output string `json:"output" mapstructure:"output"`
// FilenameEncoder is used to set the log filename encoder.
FilenameEncoder FilenameEncoder `json:"-" mapstructure:"-"`
// TimeEncoder is used to set the log time encoder.
TimeEncoder TimeEncoder `json:"-" mapstructure:"-"`
// LevelEncoder is used to set the log level encoder.
LevelEncoder LevelEncoder `json:"-" mapstructure:"-"`
// CallerEncoder is used to set the log caller encoder.
CallerEncoder CallerEncoder `json:"-" mapstructure:"-"`
}
Options Configuration for logging.
func NewOptions ¶
func NewOptions() *Options
NewOptions creates an Options with default parameters.
type TimeEncoder ¶
type TimeEncoder = zapcore.TimeEncoder
TimeEncoder is an alias for the zapcore.TimeEncoder.