zaplog

package
v0.0.0-...-2aa2d04 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 22, 2020 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AtomicLevelHandler

func AtomicLevelHandler(w http.ResponseWriter, r *http.Request)

func AtomicSetLoggerLevel

func AtomicSetLoggerLevel(lvl zapcore.Level)

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

func DPanic(msg string, fields ...zap.Field)

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

func Debug(msg string, fields ...zap.Field)

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

func Error(msg string, fields ...zap.Field)

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

func Fatal(msg string, fields ...zap.Field)

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

func Info(msg string, fields ...zap.Field)

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

func Panic(msg string, fields ...zap.Field)

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

func Warn(msg string, fields ...zap.Field)

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.

func Warnf

func Warnf(template string, args ...interface{})

Warnf uses fmt.Sprintf to log a templated message. When the template is empty string, the Warn method will be used

func Warnw

func Warnw(msg string, keysAndValues ...interface{})

Warnw logs a message with some additional context. The variadic key-value pairs are treated as they are in With.

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

func AddCallerSkip(skip int) Option

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 WithFields

func WithFields(fields ...zap.Field) Option

WithFields adds fields to the Logger.

func WithFileRotateMaxAge

func WithFileRotateMaxAge(maxAge time.Duration) Option

WithFileRotateMaxAge creates a new Option that sets the max age of a log file before it gets purged from the file system.

func WithFileRotationTime

func WithFileRotationTime(rotationTime time.Duration) Option

WithRotationTime creates a new Option that sets the time between rotation.

func WithHooks

func WithHooks(hooks ...func(zapcore.Entry) error) Option

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

func WithLogLevel(logLevel zapcore.Level) Option

WithLogLevel will set the log level to the given level and above

func WithLogPath

func WithLogPath(logPath string) Option

WithLogPath will write log the the path

func WithServiceName

func WithServiceName(serviceName string) Option

WithServiceName when in the production, the service name specify the the name of the log file dir name

func WrapCore

func WrapCore(wrapCoreFunc func(zapcore.Core) zapcore.Core) Option

WrapCore wraps or replaces the Logger's underlying zapcore.Core.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL