Documentation ¶
Index ¶
- Variables
- func Argsn(n int) string
- type CtxProvider
- type FieldFormatter
- type LEVEL
- type Levels
- type LogCtx
- type Logger
- func (l *Logger) Debug(a ...interface{})
- func (l *Logger) DebugKVs(fields ...kv.Field)
- func (l *Logger) Debugf(s string, a ...interface{})
- func (l *Logger) Error(a ...interface{})
- func (l *Logger) ErrorKVs(fields ...kv.Field)
- func (l *Logger) Errorf(s string, a ...interface{})
- func (l *Logger) Fatal(a ...interface{})
- func (l *Logger) FatalKVs(fields ...kv.Field)
- func (l *Logger) Fatalf(s string, a ...interface{})
- func (l *Logger) Info(a ...interface{})
- func (l *Logger) InfoKVs(fields ...kv.Field)
- func (l *Logger) Infof(s string, a ...interface{})
- func (l *Logger) Log(calldepth int, lvl LEVEL, a ...interface{})
- func (l *Logger) LogKVs(calldepth int, lvl LEVEL, fields ...kv.Field)
- func (l *Logger) Logf(calldepth int, lvl LEVEL, s string, a ...interface{})
- func (l *Logger) Output(ctx LogCtx, msg string, args ...interface{}) error
- func (l *Logger) Panic(a ...interface{})
- func (l *Logger) PanicKVs(fields ...kv.Field)
- func (l *Logger) Panicf(s string, a ...interface{})
- func (l *Logger) Print(a ...interface{})
- func (l *Logger) PrintKVs(fields ...kv.Field)
- func (l *Logger) Printf(s string, a ...interface{})
- func (l *Logger) SetOutput(out io.Writer)
- func (l *Logger) Trace(a ...interface{})
- func (l *Logger) TraceKVs(fields ...kv.Field)
- func (l *Logger) Tracef(s string, a ...interface{})
- func (l *Logger) Warn(a ...interface{})
- func (l *Logger) WarnKVs(fields ...kv.Field)
- func (l *Logger) Warnf(s string, a ...interface{})
- func (l *Logger) Writer() io.Writer
- type TextFormatter
Constants ¶
This section is empty.
Variables ¶
var DefaultLevels = Levels{ TRACE: "TRACE", DEBUG: "DEBUG", INFO: "INFO", WARN: "WARN", ERROR: "ERROR", FATAL: "FATAL", PANIC: "PANIC", }
Default is the default set of log levels.
Functions ¶
Types ¶
type CtxProvider ¶
type CtxProvider uint8
CtxProvider serves as an implementer of Logger.New, configurable via bit flags.
func (CtxProvider) New ¶
func (p CtxProvider) New(calldepth int) LogCtx
New will allocate a new LogCtx with current
func (*CtxProvider) SetIncludeCaller ¶
func (p *CtxProvider) SetIncludeCaller(enabled bool)
SetIncludeCaller will set whether to include caller information on LogCtx allocation.
func (*CtxProvider) SetIncludeTimestamp ¶
func (p *CtxProvider) SetIncludeTimestamp(enabled bool)
SetIncludeTimestamp will set whether to include current time on LogCtx allocation.
type FieldFormatter ¶
type FieldFormatter struct {
Levels
}
FieldFormatter is a Levels wrapper to implement the logger.Format function, in a manner that provides logging with timestamp, caller info and level prefixing log entries in key-value formatting.
func (*FieldFormatter) Format ¶
func (f *FieldFormatter) Format(buf *byteutil.Buffer, ctx LogCtx, msg string, args ...interface{})
type LEVEL ¶
type LEVEL uint8
LEVEL defines a level of logging.
type Levels ¶
Levels defines a mapping of log LEVELs to formatted level strings.
type LogCtx ¶
type LogCtx struct { Context context.Context Caller *runtime.Func Fields []kv.Field Level LEVEL Time time.Time }
LogCtx provides extra contextual information with each log message. For e.g. extra log fields, log time to include formatted timestamp, calling function information, logging level, and a context.Context which can be used to pass extra information to log hooks.
type Logger ¶
type Logger struct { // Level specifies the maximum level of log entries to output. i.e. if // it is set to INFO, then ERROR,WARN,INFO would be outputted, but DEBUG // would not. Level LEVEL // New is the function used by Logger to allocate a new LogCtx for a log entry. The calldepth is passed // for determing caller information at the point of LogCtx creation, as used by the Logger output functions. New func(calldepth int) LogCtx // Format is the function used by Logger to format each log entry. The format string and arguments // containing the main log message, and LogCtx containing any extra contextual fieilds or caller information. Format func(buf *byteutil.Buffer, ctx LogCtx, msg string, args ...interface{}) // Hooks allow modifying a log entry's LogCtx during Logger.Output(). Hooks []func(LogCtx) LogCtx // contains filtered or unexported fields }
Logger wraps an io.Writer to provide format-customizable levelled logging. All writes are mutex protected.
func NewWith ¶
NewWith returns a new Logger instance with given max log level, caller and timestamping configuration.
The default Logger function implementations are provided by: - Logger.New --> CtxProvider{}.New() - Logger.Format --> TextFormatter{}.Format()
func (*Logger) DebugKVs ¶
func (l *Logger) DebugKVs(fields ...kv.Field)
DebugKVs: see Logger.LogKVs.
func (*Logger) ErrorKVs ¶
func (l *Logger) ErrorKVs(fields ...kv.Field)
ErrorKVs: see Logger.LogKVs.
func (*Logger) Fatal ¶
func (l *Logger) Fatal(a ...interface{})
Fatal: see Logger.Log. Aftward, exits with `defer syscall.Exit(1)`.
func (*Logger) FatalKVs ¶
func (l *Logger) FatalKVs(fields ...kv.Field)
FatalKVs: see Logger.LogKVs. Aftward, exits with `defer syscall.Exit(1)`.
func (*Logger) Log ¶
Log writes provided args to the log output at provided log Calldepth is passed through to Logger.New, and determines how many frames to skip when calculating the caller.
func (*Logger) LogKVs ¶
LogKVs writes provided key-value fields to the log output. Calldepth is passed through to Logger.New, and determines how many frames to skip when calculating the caller.
func (*Logger) Logf ¶
Logf writes provided format string and args to the log output. Calldepth is passed through to Logger.New, and determines how many frames to skip when calculating the caller.
func (*Logger) Output ¶
Output will take a log entry format string with contextual information (LogCtx), and handle passing through log hooks, formatting and sending to the output io.Writer. The LogCtx level is checked directly after passing through hooks, returning early if required.
func (*Logger) Panic ¶
func (l *Logger) Panic(a ...interface{})
Panic: see Logger.Log. Aftward, exits with `defer panic(fmt.Sprintf(logger.Argsn(len(a)), a...))`.
func (*Logger) PanicKVs ¶
func (l *Logger) PanicKVs(fields ...kv.Field)
PanicKVs: see Logger.LogKVs. Aftward, exits with `defer panic(fmt.Sprintf(a...))`.
func (*Logger) Panicf ¶
Panicf: see Logger.Logf. Aftward, exits with `defer panic(fmt.Sprintf(a...))`.
func (*Logger) Print ¶
func (l *Logger) Print(a ...interface{})
Print writes provided args to the log output.
func (*Logger) PrintKVs ¶
func (l *Logger) PrintKVs(fields ...kv.Field)
PrintKVs writes provided key-value fields to the log output.
func (*Logger) TraceKVs ¶
func (l *Logger) TraceKVs(fields ...kv.Field)
TraceKVs: see Logger.LogKVs.
type TextFormatter ¶
type TextFormatter struct {
Levels
}
TextFormatter is a Levels wrapper to implement the logger.Format function, in a manner that provides logging with timestamp, caller info and level prefixing in plain printed text.
func (*TextFormatter) Format ¶
func (f *TextFormatter) Format(buf *byteutil.Buffer, ctx LogCtx, msg string, args ...interface{})