Documentation ¶
Index ¶
- func NewDevelopmentEncoderConfig() zapcore.EncoderConfig
- func NewProductionEncoderConfig() zapcore.EncoderConfig
- type Config
- type Discarder
- type Logger
- type LoggerI
- type Option
- type Syncer
- type ZapLogger
- func (log *ZapLogger) Core() zapcore.Core
- func (log *ZapLogger) DPanic(msg string, fields ...zap.Field)
- func (log *ZapLogger) DPanicCtx(ctx context.Context, msg string, fields ...zap.Field)
- func (log *ZapLogger) Debug(msg string, fields ...zap.Field)
- func (log *ZapLogger) DebugCtx(ctx context.Context, msg string, fields ...zap.Field)
- func (log *ZapLogger) Error(msg string, fields ...zap.Field)
- func (log *ZapLogger) ErrorCtx(ctx context.Context, msg string, fields ...zap.Field)
- func (log *ZapLogger) Fatal(msg string, fields ...zap.Field)
- func (log *ZapLogger) FatalCtx(ctx context.Context, msg string, fields ...zap.Field)
- func (log *ZapLogger) Info(msg string, fields ...zap.Field)
- func (log *ZapLogger) InfoCtx(ctx context.Context, msg string, fields ...zap.Field)
- func (log *ZapLogger) Named(s string) *ZapLogger
- func (log *ZapLogger) Panic(msg string, fields ...zap.Field)
- func (log *ZapLogger) PanicCtx(ctx context.Context, msg string, fields ...zap.Field)
- func (log *ZapLogger) Sync() error
- func (log *ZapLogger) Warn(msg string, fields ...zap.Field)
- func (log *ZapLogger) WarnCtx(ctx context.Context, msg string, fields ...zap.Field)
- func (log *ZapLogger) With(fields ...zap.Field) *ZapLogger
- func (log *ZapLogger) WithField(k string, v interface{}) *ZapLogger
- func (log *ZapLogger) WithFields(fields map[string]interface{}) *ZapLogger
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewDevelopmentEncoderConfig ¶
func NewDevelopmentEncoderConfig() zapcore.EncoderConfig
NewDevelopmentEncoderConfig returns an opinionated EncoderConfig for development environments.
func NewProductionEncoderConfig ¶
func NewProductionEncoderConfig() zapcore.EncoderConfig
NewProductionEncoderConfig returns an opinionated EncoderConfig for production environments.
Types ¶
type Config ¶
type Config struct { // Level is the minimum enabled logging level. Note that this is a dynamic // level, so calling Config.Level.SetLevel will atomically change the log // level of all loggers descended from this config. Level zap.AtomicLevel // Development puts the logger in development mode, which changes the // behavior of DPanicLevel and takes stack traces more liberally. Development bool // EncoderConfig sets options for the chosen encoder. See // zapcore.EncoderConfig for details. EncoderConfig zapcore.EncoderConfig // DisableCaller stops annotating logs with the calling function's file // name and line number. By default, all logs are annotated. DisableCaller bool // Encoding sets the logger's encoding. Valid values are "json" and // "console" and "all", as well as any third-party encodings registered via // RegisterEncoder. Encoding string // MaxSize is the maximum size in megabytes of the log file before it gets // rotated. It defaults to 100 megabytes. MaxSize int // 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 // LocalTime determines if the time used for formatting the timestamps in // backup files is the computer's local time. The default is to use UTC // time. LocalTime bool // Compress determines if the rotated log files should be compressed // using gzip. The default is not to perform compression. Compress bool // Filename is the file to write logs to. Backup log files will be retained // in the same directory. It uses <processname>-lumberjack.log in // os.TempDir() if empty. Filename string // 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 Interval time.Duration }
func NewDevelopmentConfig ¶
func NewDevelopmentConfig() Config
NewDevelopmentConfig is a reasonable development logging configuration. Logging is enabled at DebugLevel and above.
It enables development mode (which makes DPanicLevel logs panic), uses a console encoder, writes to standard error, and disables sampling. Stack traces are automatically included on logs of WarnLevel and above.
func NewProductionConfig ¶
func NewProductionConfig() Config
NewProductionConfig is a reasonable production logging configuration. Logging is enabled at InfoLevel and above.
It uses a JSON encoder, writes to standard error, and enables sampling. Stack traces are automatically included on logs of ErrorLevel and above.
type Logger ¶
type Logger = ZapLogger
Logger logger
func NewNop ¶
func NewNop() *Logger
NewNop returns a no-op Logger. It never writes out logs or internal errors, and it never runs user-defined hooks.
Using WithOptions to replace the Core or error output of a no-op Logger can re-enable logging.
func (*Logger) Check ¶
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) Level ¶
Level reports the minimum enabled level for this logger.
For NopLoggers, this is zapcore.InvalidLevel.
func (*Logger) Log ¶
Log logs a message at the specified level. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.
func (*Logger) WithOptions ¶
WithOptions clones the current Logger, applies the supplied Options, and returns the resulting Logger. It's safe to use concurrently.
type LoggerI ¶
type LoggerI interface { Debug(msg string, fields ...zap.Field) Info(msg string, fields ...zap.Field) Warn(msg string, fields ...zap.Field) Error(msg string, fields ...zap.Field) Fatal(msg string, fields ...zap.Field) Panic(msg string, fields ...zap.Field) DPanic(msg string, fields ...zap.Field) DebugCtx(ctx context.Context, msg string, fields ...zap.Field) InfoCtx(ctx context.Context, msg string, fields ...zap.Field) WarnCtx(ctx context.Context, msg string, fields ...zap.Field) ErrorCtx(ctx context.Context, msg string, fields ...zap.Field) FatalCtx(ctx context.Context, msg string, fields ...zap.Field) PanicCtx(ctx context.Context, msg string, fields ...zap.Field) DPanicCtx(ctx context.Context, msg string, fields ...zap.Field) }
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
An Option configures a Logger.
func AddCaller ¶
func AddCaller() Option
AddCaller configures the Logger to annotate each message with the filename, line number, and function name of zap's caller. See also WithCaller.
func AddCallerSkip ¶
AddCallerSkip increases the number of callers skipped by caller annotation (as enabled by the AddCaller option). When building wrappers around the Logger and SugaredLogger, supplying this Option prevents zap from always reporting the wrapper code as the caller.
func AddContext ¶
AddContext it is used to decide which of the values in the context be used. After deciding the context value will call the set function, used to read the entire contents of the context value on the key
func AddStacktrace ¶
func AddStacktrace(lvl zapcore.LevelEnabler) Option
AddStacktrace configures the Logger to record a stack trace for all messages at or above a given level.
func Development ¶
func Development() Option
Development puts the logger in development mode, which makes DPanic-level logs panic instead of simply logging an error.
func WithCaller ¶
WithCaller configures the Logger to annotate each message with the filename, line number, and function name of zap's caller, or not, depending on the value of enabled. This is a generalized form of AddCaller.
type Syncer ¶
type Syncer struct {
// contains filtered or unexported fields
}
A Syncer is a spy for the Sync portion of zapcore.WriteSyncer.
type ZapLogger ¶
type ZapLogger struct { Ctx *inmemCtx // contains filtered or unexported fields }
A ZapLogger provides fast, leveled, structured logging. All methods are safe for concurrent use.
func New ¶
New constructs a new ZapLogger from the provided zapcore.Core and Options. If the passed zapcore.Core is nil, it falls back to using a no-op implementation.
func (*ZapLogger) DPanicCtx ¶
DPanicCtx with context logs a message at level DPanic on the ZapLogger.
func (*ZapLogger) DebugCtx ¶
DebugCtx with context logs a message at level DebugMode on the ZapLogger.
func (*ZapLogger) WithFields ¶
WithFields return a log with extra fields.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package buffer provides a thin wrapper around a byte slice.
|
Package buffer provides a thin wrapper around a byte slice. |
pkg
|
|
diode
Package diode provides a thread-safe, lock-free, non-blocking io.Writer wrapper.
|
Package diode provides a thread-safe, lock-free, non-blocking io.Writer wrapper. |