Documentation ¶
Index ¶
- Variables
- func Debug(args ...interface{})
- func Debugf(template string, args ...interface{})
- func Debugw(msg string, keysAndValues ...interface{})
- func DefaultTimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder)
- func Error(args ...interface{})
- func Errorf(template string, args ...interface{})
- func Errorw(msg string, keysAndValues ...interface{})
- func Fatal(args ...interface{})
- func Fatalf(template string, args ...interface{})
- func Fatalw(msg string, keysAndValues ...interface{})
- func GetLevel() zapcore.Level
- func Info(args ...interface{})
- func Infof(template string, args ...interface{})
- func Infow(msg string, keysAndValues ...interface{})
- func L() *zap.Logger
- func Level() zap.AtomicLevel
- func NewTextCore(enc zapcore.Encoder, ws zapcore.WriteSyncer, enab zapcore.LevelEnabler) zapcore.Core
- func NewTextEncoder(encoderConfig *zapcore.EncoderConfig, spaced bool, disableErrorVerbose bool) zapcore.Encoder
- func NewTextEncoderByConfig(cfg *Config) zapcore.Encoder
- func Panic(args ...interface{})
- func Panicf(template string, args ...interface{})
- func Panicw(msg string, keysAndValues ...interface{})
- func Print(args ...interface{})
- func Printf(template string, args ...interface{})
- func R() *utils.ReconfigurableRateLimiter
- func RatedDebug(cost float64, msg string, fields ...zap.Field) bool
- func RatedInfo(cost float64, msg string, fields ...zap.Field) bool
- func RatedWarn(cost float64, msg string, fields ...zap.Field) bool
- func ReplaceGlobals(logger *zap.Logger, props *ZapProperties)
- func S() *zap.SugaredLogger
- func SetLevel(l zapcore.Level)
- func ShortCallerEncoder(caller zapcore.EntryCaller, enc zapcore.PrimitiveArrayEncoder)
- func Sync() error
- func Warn(args ...interface{})
- func Warnf(template string, args ...interface{})
- func Warnw(msg string, keysAndValues ...interface{})
- func WithDebugLevel(ctx context.Context) context.Context
- func WithErrorLevel(ctx context.Context) context.Context
- func WithFatalLevel(ctx context.Context) context.Context
- func WithFields(ctx context.Context, fields ...zap.Field) context.Context
- func WithInfoLevel(ctx context.Context) context.Context
- func WithModule(ctx context.Context, module string) context.Context
- func WithReqID(ctx context.Context, reqID int64) context.Context
- func WithTraceID(ctx context.Context, traceID string) context.Context
- func WithWarnLevel(ctx context.Context) context.Context
- type Config
- type EncoderConfig
- type FileLogConfig
- type MLogger
- func (l *MLogger) RatedDebug(cost float64, msg string, fields ...zap.Field) bool
- func (l *MLogger) RatedInfo(cost float64, msg string, fields ...zap.Field) bool
- func (l *MLogger) RatedWarn(cost float64, msg string, fields ...zap.Field) bool
- func (l *MLogger) With(fields ...zap.Field) *MLogger
- func (l *MLogger) WithRateGroup(groupName string, creditPerSecond, maxBalance float64) *MLogger
- type ZapProperties
- func InitLogger(cfg *Config, opts ...zap.Option) (*zap.Logger, *ZapProperties, error)
- func InitLoggerWithWriteSyncer(cfg *Config, output zapcore.WriteSyncer, opts ...zap.Option) (*zap.Logger, *ZapProperties, error)
- func InitTestLogger(t zaptest.TestingT, cfg *Config, opts ...zap.Option) (*zap.Logger, *ZapProperties, error)
Constants ¶
This section is empty.
Variables ¶
var CtxLogKey = ctxLogKeyType{}
var (
// Get retrieves a buffer from the pool, creating one if necessary.
Get = _pool.Get
)
Functions ¶
func DefaultTimeEncoder ¶
func DefaultTimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder)
DefaultTimeEncoder serializes time.Time to a human-readable formatted string
func L ¶
L returns the global Logger, which can be reconfigured with ReplaceGlobals. It's safe for concurrent use.
func Level ¶
func Level() zap.AtomicLevel
func NewTextCore ¶
func NewTextCore(enc zapcore.Encoder, ws zapcore.WriteSyncer, enab zapcore.LevelEnabler) zapcore.Core
NewTextCore creates a Core that writes logs to a WriteSyncer.
func NewTextEncoder ¶
func NewTextEncoderByConfig ¶
NewTextEncoderByConfig creates a fast, low-allocation Text encoder with config. The encoder appropriately escapes all field keys and values.
func RatedDebug ¶
RatedDebug print logs at debug level it limit log print to avoid too many logs return true if log successfully
func RatedInfo ¶
RatedInfo print logs at info level it limit log print to avoid too many logs return true if log successfully
func RatedWarn ¶
RatedWarn print logs at warn level it limit log print to avoid too many logs return true if log successfully
func ReplaceGlobals ¶
func ReplaceGlobals(logger *zap.Logger, props *ZapProperties)
ReplaceGlobals replaces the global Logger and SugaredLogger. It's safe for concurrent use.
func S ¶
func S() *zap.SugaredLogger
S returns the global SugaredLogger, which can be reconfigured with ReplaceGlobals. It's safe for concurrent use.
func ShortCallerEncoder ¶
func ShortCallerEncoder(caller zapcore.EntryCaller, enc zapcore.PrimitiveArrayEncoder)
ShortCallerEncoder serializes a caller in file:line format.
func WithDebugLevel ¶
WithDebugLevel returns context with a debug level enabled logger. Notes that it will overwrite previous attached logger within context
func WithErrorLevel ¶
WithErrorLevel returns context with a error level enabled logger. Notes that it will overwrite previous attached logger within context
func WithFatalLevel ¶
WithFatalLevel returns context with a fatal level enabled logger. Notes that it will overwrite previous attached logger within context
func WithFields ¶
WithFields returns a context with fields attached
func WithInfoLevel ¶
WithInfoLevel returns context with a info level enabled logger. Notes that it will overwrite previous attached logger within context
func WithModule ¶
WithModule adds given module field to the logger in ctx
func WithTraceID ¶
WithTraceID returns a context with trace_id attached
Types ¶
type Config ¶
type Config struct { // Log level. Level string `toml:"level" json:"level"` // grpc log level GrpcLevel string `toml:"grpc-level" json:"grpc-level"` // Log format. one of json, text, or console. Format string `toml:"format" json:"format"` // Disable automatic timestamps in output. DisableTimestamp bool `toml:"disable-timestamp" json:"disable-timestamp"` // Stdout enable or not. Stdout bool `toml:"stdout" json:"stdout"` // File log config. File FileLogConfig `toml:"file" json:"file"` // Encoder config. Encoder EncoderConfig `toml:"encoder" json:"encoder"` // Development puts the logger in development mode, which changes the // behavior of DPanicLevel and takes stacktraces more liberally. Development bool `toml:"development" json:"development"` // DisableCaller stops annotating logs with the calling function's file // name and line number. By default, all logs are annotated. DisableCaller bool `toml:"disable-caller" json:"disable-caller"` // DisableStacktrace completely disables automatic stacktrace capturing. By // default, stacktraces are captured for WarnLevel and above logs in // development and ErrorLevel and above in production. DisableStacktrace bool `toml:"disable-stacktrace" json:"disable-stacktrace"` // DisableErrorVerbose stops annotating logs with the full verbose error // message. DisableErrorVerbose bool `toml:"disable-error-verbose" json:"disable-error-verbose"` // SamplingConfig sets a sampling strategy for the logger. Sampling caps the // global CPU and I/O load that logging puts on your process while attempting // to preserve a representative subset of your logs. // // Values configured here are per-second. See zapcore.NewSampler for details. Sampling *zap.SamplingConfig `toml:"sampling" json:"sampling"` }
Config serializes log related config in toml/json.
type EncoderConfig ¶
type EncoderConfig struct { // Set the keys used for each log entry. If any key is empty, that portion // of the entry is omitted. MessageKey string `json:"messageKey" yaml:"messageKey"` LevelKey string `json:"levelKey" yaml:"levelKey"` TimeKey string `json:"timeKey" yaml:"timeKey"` NameKey string `json:"nameKey" yaml:"nameKey"` CallerKey string `json:"callerKey" yaml:"callerKey"` FunctionKey string `json:"functionKey" yaml:"functionKey"` StacktraceKey string `json:"stacktraceKey" yaml:"stacktraceKey"` SkipLineEnding bool `json:"skipLineEnding" yaml:"skipLineEnding"` LineEnding string `json:"lineEnding" yaml:"lineEnding"` // Configure the primitive representations of common complex types. For // example, some users may want all time.Times serialized as floating-point // seconds since epoch, while others may prefer ISO8601 strings. EncodeLevel zapcore.LevelEncoder `json:"levelEncoder" yaml:"levelEncoder"` EncodeTime zapcore.TimeEncoder `json:"timeEncoder" yaml:"timeEncoder"` EncodeDuration zapcore.DurationEncoder `json:"durationEncoder" yaml:"durationEncoder"` EncodeCaller zapcore.CallerEncoder `json:"callerEncoder" yaml:"callerEncoder"` // Unlike the other primitive type encoders, EncodeName is optional. The // zero value falls back to FullNameEncoder. EncodeName zapcore.NameEncoder `json:"nameEncoder" yaml:"nameEncoder"` //// Configure the encoder for interface{} type objects. //// If not provided, objects are encoded using json.Encoder //NewReflectedEncoder func(io.Writer) zapcore.ReflectedEncoder `json:"-" yaml:"-"` // Configures the field separator used by the console encoder. Defaults // to tab. ConsoleSeparator string `json:"consoleSeparator" yaml:"consoleSeparator"` }
type FileLogConfig ¶
type FileLogConfig struct { // Log rootpath RootPath string `toml:"rootpath" json:"rootpath"` // Log filename, leave empty to disable file log. Filename string `toml:"filename" json:"filename"` // Max size for a single file, in MB. MaxSize int `toml:"max-size" json:"max-size"` // Max log keep days, default is never deleting. MaxDays int `toml:"max-days" json:"max-days"` // Maximum number of old log files to retain. MaxBackups int `toml:"max-backups" json:"max-backups"` // Compress function for rotated files. // Currently only `gzip` and empty are supported, empty means compression disabled. Compress string `toml:"compress" json:"compress"` }
FileLogConfig serializes file log related config in toml/json.
type MLogger ¶
MLogger is a wrapper type of zap.Logger.
func With ¶
With creates a child logger and adds structured context to it. Fields added to the child don't affect the parent, and vice versa.
func (*MLogger) RatedDebug ¶
RatedDebug calls log.Debug with RateLimiter.
type ZapProperties ¶
type ZapProperties struct { Core zapcore.Core Syncer zapcore.WriteSyncer Level zap.AtomicLevel }
ZapProperties records some information about zap.
func InitLogger ¶
InitLogger initializes a zap logger.
func InitLoggerWithWriteSyncer ¶
func InitLoggerWithWriteSyncer(cfg *Config, output zapcore.WriteSyncer, opts ...zap.Option) (*zap.Logger, *ZapProperties, error)
InitLoggerWithWriteSyncer initializes a zap logger with specified write syncer.