Documentation ¶
Overview ¶
Package log is a structured logger for Go, based on https://github.com/uber-go/zap.
Index ¶
- 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 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 Info(msg string, keysAndValues ...interface{})
- func Infof(template string, args ...interface{})
- func Infot(msg string, fields ...Field)
- func Panic(msg string, keysAndValues ...interface{})
- func Panicf(template string, args ...interface{})
- func Panict(msg string, fields ...Field)
- func Warn(msg string, keysAndValues ...interface{})
- func Warnf(template string, args ...interface{})
- func Warnt(msg string, fields ...Field)
- type DebugLogger
- type Field
- type FilenameEncoder
- type InfoLogger
- type Interface
- type Level
- 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) 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) 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) 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 ¶
This section is empty.
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.
var ( // EncodedFilename filename for logging when DisableFile is false. EncodedFilename string )
Functions ¶
func Close ¶ added in v0.1.11
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 <processname>-<date>.log.
func DefaultTimeEncoder ¶
func DefaultTimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder)
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 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.
Types ¶
type DebugLogger ¶ added in v0.1.4
type FilenameEncoder ¶
type FilenameEncoder func() string
FilenameEncoder log filename encoder, return the fullname of the log file.
type InfoLogger ¶ added in v0.1.4
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 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) DebugLogger ¶ added in v0.1.4
func (l *Logger) DebugLogger() DebugLogger
func (*Logger) InfoLogger ¶ added in v0.1.4
func (l *Logger) InfoLogger() InfoLogger
func (*Logger) WithValues ¶
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 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"` // 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 log filename encoder FilenameEncoder FilenameEncoder // TimeEncoder time encoder TimeEncoder TimeEncoder }
Options Configuration for logging.
type TimeEncoder ¶
type TimeEncoder = zapcore.TimeEncoder
TimeEncoder is an alias for the zapcore.TimeEncoder.