Documentation ¶
Overview ¶
Package log is a wrapper around the zap logger, providing easier integration of logging into applications and packages.
Index ¶
- Constants
- Variables
- func Check(lvl zapcore.Level, msg string) *zapcore.CheckedEntry
- func Core() zapcore.Core
- func Debug(msg string, fields ...zap.Field)
- func Error(msg string, fields ...zap.Field)
- func Fatal(msg string, fields ...zap.Field)
- func Info(msg string, fields ...zap.Field)
- func Log() *zap.Logger
- func Named(s string) *zap.Logger
- func Panic(msg string, fields ...zap.Field)
- func Register(l *Logger) error
- func RegisterFromFlags(f Flags) (func(), error)
- func Sync()
- func Warn(msg string, fields ...zap.Field)
- func With(fields ...zap.Field) *zap.Logger
- func WithOptions(opts ...zap.Option) *zap.Logger
- type Config
- type Flags
- type Level
- type Logger
Constants ¶
const ( // 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 // PanicLevel logs a message, then panics. PanicLevel = zapcore.PanicLevel // FatalLevel logs a message, then calls os.Exit(1). FatalLevel = zapcore.FatalLevel )
Variables ¶
var Levels = map[string]Level{ "debug": DebugLevel, "info": InfoLevel, "warn": WarnLevel, "error": ErrorLevel, "panic": PanicLevel, "fatal": FatalLevel, }
Levels contains a map of level names with their associated Level type.
Functions ¶
func Check ¶
func Check(lvl zapcore.Level, msg string) *zapcore.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 Debug ¶
Debug logs a message at DebugLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.
func Error ¶
Error logs a message at ErrorLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.
func Fatal ¶
Fatal logs a message at FatalLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.
The logger then calls os.Exit(1), even if logging at FatalLevel is disabled.
func Info ¶
Info logs a message at InfoLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.
func Named ¶
Named adds a new path segment to the logger's name. Segments are joined by periods. By default, Loggers are unnamed.
func Panic ¶
Panic logs a message at PanicLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.
The logger then panics, even if logging at PanicLevel is disabled.
func Register ¶
Register registers a Logger globally. Register can be called multiple times, but only the first call will register a logger, all subsequent calls are a no-op.
func RegisterFromFlags ¶
RegisterFromFlags creates and registers a new logger using CLI flags.
func Sync ¶
func Sync()
Sync calls the underlying Core's Sync method, flushing any buffered log entries. Applications should take care to call Sync before exiting.
func Warn ¶
Warn logs a message at WarnLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.
Types ¶
type Config ¶
type Config struct { // Encoder is the encoder that should be used to encode log output. Encoder zapcore.Encoder `json:"encoder"` // Level is the level at which logs will be output. Level Level `json:"level"` // Output is the writer that encoded logs will be output to. Output io.Writer `json:"output"` }
Config represents the configuration for a Logger.
type Flags ¶
type Flags struct { Encoder string `enum:"console,json,logfmt" default:"logfmt"` Level string `enum:"debug,info,warn,error,panic,fatal" default:"info"` }
Flags are CLI flags for use with [kong](https://github.com/alecthomas/kong)