Documentation ¶
Index ¶
- func AtomicLevelHandler(w http.ResponseWriter, r *http.Request)
- func AtomicSetLoggerLevel(lvl zapcore.Level)
- func CustomizedTimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder)
- func DPanic(msg string, fields ...zap.Field)
- func DPanicf(template string, args ...interface{})
- func DPanicw(msg string, keysAndValues ...interface{})
- func Debug(msg string, fields ...zap.Field)
- func Debugf(template string, args ...interface{})
- func Debugw(msg string, keysAndValues ...interface{})
- func Error(msg string, fields ...zap.Field)
- func Errorf(template string, args ...interface{})
- func Errorw(msg string, keysAndValues ...interface{})
- func Fatal(msg string, fields ...zap.Field)
- func Fatalf(template string, args ...interface{})
- func Fatalw(msg string, keysAndValues ...interface{})
- func Info(msg string, fields ...zap.Field)
- func Infof(template string, args ...interface{})
- func Infow(msg string, keysAndValues ...interface{})
- func InitLogger(opts ...Option)
- func NewEncoderConfig() zapcore.EncoderConfig
- func NewLogger(opts ...Option) (*zap.Logger, zap.AtomicLevel)
- func NewSugaredLogger(opts ...Option) (*zap.SugaredLogger, zap.AtomicLevel)
- func Panic(msg string, fields ...zap.Field)
- func Panicf(template string, args ...interface{})
- func Panicw(msg string, keysAndValues ...interface{})
- func Sync() error
- func Warn(msg string, fields ...zap.Field)
- func Warnf(template string, args ...interface{})
- func Warnw(msg string, keysAndValues ...interface{})
- type Option
- func AddCaller() Option
- func AddCallerSkip(skip int) Option
- func AddStacktrace(lvl zapcore.LevelEnabler) Option
- func Development() Option
- func WithErrorOutput(w zapcore.WriteSyncer) Option
- func WithFields(fields ...zap.Field) Option
- func WithFileRotateMaxAge(maxAge time.Duration) Option
- func WithFileRotationTime(rotationTime time.Duration) Option
- func WithHooks(hooks ...func(zapcore.Entry) error) Option
- func WithLogLevel(logLevel zapcore.Level) Option
- func WithLogPath(logPath string) Option
- func WithServiceName(serviceName string) Option
- func WrapCore(wrapCoreFunc func(zapcore.Core) zapcore.Core) Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AtomicLevelHandler ¶
func AtomicLevelHandler(w http.ResponseWriter, r *http.Request)
func AtomicSetLoggerLevel ¶
ChangeLoggerLevel will atomically change the log level
func CustomizedTimeEncoder ¶
func CustomizedTimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder)
CustomizedTimeEncoder new a zap customized time encoder
func DPanic ¶
DPanic logs a message at DPanicLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.
If the logger is in development mode, it then panics (DPanic means "development panic"). This is useful for catching errors that are recoverable, but shouldn't ever happen.
func DPanicf ¶
func DPanicf(template string, args ...interface{})
DPanicf uses fmt.Sprintf to log a templated message. In development, the logger then panics. (See DPanicLevel for details.) When the template is empty string, the DPanic method will be used
func DPanicw ¶
func DPanicw(msg string, keysAndValues ...interface{})
DPanicw logs a message with some additional context. In development, the logger then panics. (See DPanicLevel for details.) The variadic key-value pairs are treated as they are in With.
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 Debugf ¶
func Debugf(template string, args ...interface{})
Debugf uses fmt.Sprintf to log a templated message. When the template is empty string, the Debug method will be used
func Debugw ¶
func Debugw(msg string, keysAndValues ...interface{})
Debugw logs a message with some additional context. The variadic key-value pairs are treated as they are in With.
When debug-level logging is disabled, this is much faster than
s.With(keysAndValues).Debug(msg)
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 Errorf ¶
func Errorf(template string, args ...interface{})
Errorf uses fmt.Sprintf to log a templated message. When the template is empty string, the Error method will be used
func Errorw ¶
func Errorw(msg string, keysAndValues ...interface{})
Errorw logs a message with some additional context. The variadic key-value pairs are treated as they are in With.
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 Fatalf ¶
func Fatalf(template string, args ...interface{})
Fatalf uses fmt.Sprintf to log a templated message, then calls os.Exit. When the template is empty string, the Fatal method will be used
func Fatalw ¶
func Fatalw(msg string, keysAndValues ...interface{})
Fatalw logs a message with some additional context, then calls os.Exit. The variadic key-value pairs are treated as they are in With.
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 Infof ¶
func Infof(template string, args ...interface{})
Infof uses fmt.Sprintf to log a templated message. When the template is empty string, the Info method will be used
func Infow ¶
func Infow(msg string, keysAndValues ...interface{})
Infow logs a message with some additional context. The variadic key-value pairs are treated as they are in With.
func InitLogger ¶
func InitLogger(opts ...Option)
InitLogger initialize a global logger and sugar logger to use
func NewEncoderConfig ¶
func NewEncoderConfig() zapcore.EncoderConfig
NewEncoderConfig new a zap encoder config
func NewLogger ¶
func NewLogger(opts ...Option) (*zap.Logger, zap.AtomicLevel)
NewLogger new a zap logger and return its atomic level If the logPath is empty (use WithLogPath) or the development (use Development) is set, the logger will write log to os.stderr. In production, you have better specify the serviceName(use WithServiceName).
func NewSugaredLogger ¶
func NewSugaredLogger(opts ...Option) (*zap.SugaredLogger, zap.AtomicLevel)
NewSugaredLogger new a sugar logger for using method such as log.Infof(template string, args ...interface{}) or log.Infow(msg string, keysAndValues ...interface{})
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 Panicf ¶
func Panicf(template string, args ...interface{})
Panicf uses fmt.Sprintf to log a templated message, then panics. When the template is empty string, the Panic method will be used
func Panicw ¶
func Panicw(msg string, keysAndValues ...interface{})
Panicw logs a message with some additional context, then panics. The variadic key-value pairs are treated as they are in With.
func Sync ¶
func Sync() error
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 Option ¶
type Option interface {
// contains filtered or unexported methods
}
func AddCaller ¶
func AddCaller() Option
AddCaller configures the Logger to annotate each message with the filename and line number of zap's caller.
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 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 WithErrorOutput ¶
func WithErrorOutput(w zapcore.WriteSyncer) Option
WithErrorOutput sets the destination for errors generated by the Logger. Note that this option only affects internal errors; for sample code that sends error-level logs to a different location from info- and debug-level logs, see the package-level AdvancedConfiguration example.
The supplied WriteSyncer must be safe for concurrent use. The Open and zapcore.Lock functions are the simplest ways to protect files with a mutex.
func WithFileRotateMaxAge ¶
WithFileRotateMaxAge creates a new Option that sets the max age of a log file before it gets purged from the file system.
func WithFileRotationTime ¶
WithRotationTime creates a new Option that sets the time between rotation.
func WithHooks ¶
WithHooks registers functions which will be called each time the Logger writes out an Entry. Repeated use of WithHooks is additive.
WithHooks are useful for simple side effects, like capturing metrics for the number of emitted logs. More complex side effects, including anything that requires access to the Entry's structured fields, should be implemented as a zapcore.Core instead. See zapcore.RegisterHooks for details.
func WithLogLevel ¶
WithLogLevel will set the log level to the given level and above
func WithServiceName ¶
WithServiceName when in the production, the service name specify the the name of the log file dir name