Documentation ¶
Index ¶
- Constants
- Variables
- func DPanic(args ...any)
- func DPanicf(template string, args ...any)
- func DPanicw(msg string, keysAndValues ...any)
- func Debug(args ...any)
- func Debugf(template string, args ...any)
- func Debugw(msg string, keysAndValues ...any)
- func Enabled(lvl zapcore.Level) bool
- func Error(args ...any)
- func Errorf(template string, args ...any)
- func Errorw(msg string, keysAndValues ...any)
- func Fatal(args ...any)
- func Fatalf(template string, args ...any)
- func Fatalw(msg string, keysAndValues ...any)
- func GetLevel() zapcore.Level
- func Info(args ...any)
- func Infof(template string, args ...any)
- func Infow(msg string, keysAndValues ...any)
- func New(opts ...Option) (*zap.Logger, zap.AtomicLevel)
- func Panic(args ...any)
- func Panicf(template string, args ...any)
- func Panicw(msg string, keysAndValues ...any)
- func ReplaceGlobals(logger *Log)
- func SetLevelWithText(text string) error
- func Sync() error
- func V(lvl int) bool
- func Warn(args ...any)
- func Warnf(template string, args ...any)
- func Warnw(msg string, keysAndValues ...any)
- type Config
- type Field
- type Level
- type Log
- func Named(name string) *Log
- func NewLogger(opts ...Option) *Log
- func NewLoggerWith(logger *zap.Logger, lv zap.AtomicLevel) *Log
- func SetDefaultValuer(vs ...Valuer) *Log
- func SetLevel(lv zapcore.Level) *Log
- func With(fields ...Field) *Log
- func WithContext(ctx context.Context) *Log
- func WithNewValuer(fs ...Valuer) *Log
- func WithValuer(vs ...Valuer) *Log
- func (l *Log) DPanic(args ...any)
- func (l *Log) DPanicf(template string, args ...any)
- func (l *Log) DPanicw(msg string, keysAndValues ...any)
- func (l *Log) Debug(args ...any)
- func (l *Log) Debugf(template string, args ...any)
- func (l *Log) Debugw(msg string, keysAndValues ...any)
- func (l *Log) Enabled(lvl zapcore.Level) bool
- func (l *Log) Error(args ...any)
- func (l *Log) Errorf(template string, args ...any)
- func (l *Log) Errorw(msg string, keysAndValues ...any)
- func (l *Log) Fatal(args ...any)
- func (l *Log) Fatalf(template string, args ...any)
- func (l *Log) Fatalw(msg string, keysAndValues ...any)
- func (l *Log) GetLevel() zapcore.Level
- func (l *Log) Info(args ...any)
- func (l *Log) Infof(template string, args ...any)
- func (l *Log) Infow(msg string, keysAndValues ...any)
- func (l *Log) Logger() *zap.Logger
- func (l *Log) Named(name string) *Log
- func (l *Log) Panic(args ...any)
- func (l *Log) Panicf(template string, args ...any)
- func (l *Log) Panicw(msg string, keysAndValues ...any)
- func (l *Log) SetDefaultValuer(fs ...Valuer) *Log
- func (l *Log) SetLevel(lv zapcore.Level) *Log
- func (l *Log) SetLevelWithText(text string) error
- func (l *Log) Sugar() *zap.SugaredLogger
- func (l *Log) Sync() error
- func (l *Log) V(lvl int) bool
- func (l *Log) Warn(args ...any)
- func (l *Log) Warnf(template string, args ...any)
- func (l *Log) Warnw(msg string, keysAndValues ...any)
- func (l *Log) With(fields ...Field) *Log
- func (l *Log) WithContext(ctx context.Context) *Log
- func (l *Log) WithNewValuer(fs ...Valuer) *Log
- func (l *Log) WithValuer(fs ...Valuer) *Log
- type Option
- func WithAdapter(adapter string, writer ...io.Writer) Option
- func WithAddCaller(b bool) Option
- func WithConfig(cfg Config) Option
- func WithEnableCompress() Option
- func WithEnableLocalTime() Option
- func WithFilename(filename string) Option
- func WithFormat(format string) Option
- func WithLevel(level string) Option
- func WithMaxAge(maxAge int) Option
- func WithMaxBackups(maxBackups int) Option
- func WithMaxSize(maxSize int) Option
- func WithPath(path string) Option
- func WithStack(stack bool) Option
- type Valuer
- func App(v string) Valuer
- func Component(v string) Valuer
- func FromAny(key string, vf func(context.Context) any) Valuer
- func FromBinary(key string, vf func(context.Context) []byte) Valuer
- func FromBool(key string, vf func(context.Context) bool) Valuer
- func FromBoolp(key string, vf func(context.Context) *bool) Valuer
- func FromByteString(key string, vf func(context.Context) []byte) Valuer
- func FromComplex128(key string, vf func(context.Context) complex128) Valuer
- func FromComplex128p(key string, vf func(context.Context) *complex128) Valuer
- func FromComplex64(key string, vf func(context.Context) complex64) Valuer
- func FromComplex64p(key string, vf func(context.Context) *complex64) Valuer
- func FromDuration(key string, vf func(context.Context) time.Duration) Valuer
- func FromDurationp(key string, vf func(context.Context) *time.Duration) Valuer
- func FromFloat32(key string, vf func(context.Context) float32) Valuer
- func FromFloat32p(key string, vf func(context.Context) *float32) Valuer
- func FromFloat64(key string, vf func(context.Context) float64) Valuer
- func FromFloat64p(key string, vf func(context.Context) *float64) Valuer
- func FromInt(key string, vf func(context.Context) int) Valuer
- func FromInt16(key string, vf func(context.Context) int16) Valuer
- func FromInt16p(key string, vf func(context.Context) *int16) Valuer
- func FromInt32(key string, vf func(context.Context) int32) Valuer
- func FromInt32p(key string, vf func(context.Context) *int32) Valuer
- func FromInt64(key string, vf func(context.Context) int64) Valuer
- func FromInt64p(key string, vf func(context.Context) *int64) Valuer
- func FromInt8(key string, vf func(context.Context) int8) Valuer
- func FromInt8p(key string, vf func(context.Context) *int8) Valuer
- func FromIntp(key string, vf func(context.Context) *int) Valuer
- func FromNamespace(key string) Valuer
- func FromReflect(key string, vf func(context.Context) any) Valuer
- func FromStack(key string) Valuer
- func FromStackSkip(key string, skip int) Valuer
- func FromString(key string, vf func(context.Context) string) Valuer
- func FromStringer(key string, vf func(context.Context) fmt.Stringer) Valuer
- func FromStringp(key string, vf func(context.Context) *string) Valuer
- func FromTime(key string, vf func(context.Context) time.Time) Valuer
- func FromTimep(key string, vf func(context.Context) *time.Time) Valuer
- func FromUint(key string, vf func(context.Context) uint) Valuer
- func FromUint16(key string, vf func(context.Context) uint16) Valuer
- func FromUint16p(key string, vf func(context.Context) *uint16) Valuer
- func FromUint32(key string, vf func(context.Context) uint32) Valuer
- func FromUint32p(key string, vf func(context.Context) *uint32) Valuer
- func FromUint64(key string, vf func(context.Context) uint64) Valuer
- func FromUint64p(key string, vf func(context.Context) *uint64) Valuer
- func FromUint8(key string, vf func(context.Context) uint8) Valuer
- func FromUint8p(key string, vf func(context.Context) *uint8) Valuer
- func FromUintp(key string, vf func(context.Context) *uint) Valuer
- func FromUintptr(key string, vf func(context.Context) uintptr) Valuer
- func FromUintptrp(key string, vf func(context.Context) *uintptr) Valuer
- func ImmutAny(key string, v any) Valuer
- func ImmutBinary(key string, v []byte) Valuer
- func ImmutBool(key string, v bool) Valuer
- func ImmutBoolp(key string, v *bool) Valuer
- func ImmutByteString(key string, v []byte) Valuer
- func ImmutComplex128(key string, v complex128) Valuer
- func ImmutComplex128p(key string, v *complex128) Valuer
- func ImmutComplex64(key string, v complex64) Valuer
- func ImmutComplex64p(key string, v *complex64) Valuer
- func ImmutDuration(key string, v time.Duration) Valuer
- func ImmutDurationp(key string, v *time.Duration) Valuer
- func ImmutFloat32(key string, v float32) Valuer
- func ImmutFloat32p(key string, v *float32) Valuer
- func ImmutFloat64(key string, v float64) Valuer
- func ImmutFloat64p(key string, v *float64) Valuer
- func ImmutInt(key string, v int) Valuer
- func ImmutInt16(key string, v int16) Valuer
- func ImmutInt16p(key string, v *int16) Valuer
- func ImmutInt32(key string, v int32) Valuer
- func ImmutInt32p(key string, v *int32) Valuer
- func ImmutInt64(key string, v int64) Valuer
- func ImmutInt64p(key string, v *int64) Valuer
- func ImmutInt8(key string, v int8) Valuer
- func ImmutInt8p(key string, v *int8) Valuer
- func ImmutIntp(key string, v *int) Valuer
- func ImmutReflect(key string, v any) Valuer
- func ImmutString(key string, v string) Valuer
- func ImmutStringer(key string, v fmt.Stringer) Valuer
- func ImmutStringp(key string, v *string) Valuer
- func ImmutTime(key string, v time.Time) Valuer
- func ImmutTimep(key string, v *time.Time) Valuer
- func ImmutUint(key string, v uint) Valuer
- func ImmutUint16(key string, v uint16) Valuer
- func ImmutUint16p(key string, v *uint16) Valuer
- func ImmutUint32(key string, v uint32) Valuer
- func ImmutUint32p(key string, v *uint32) Valuer
- func ImmutUint64(key string, v uint64) Valuer
- func ImmutUint64p(key string, v *uint64) Valuer
- func ImmutUint8(key string, v uint8) Valuer
- func ImmutUint8p(key string, v *uint8) Valuer
- func ImmutUintp(key string, v *uint) Valuer
- func ImmutUintptr(key string, v uintptr) Valuer
- func ImmutUintptrp(key string, v *uintptr) Valuer
- func Kind(v string) Valuer
- func Module(v string) Valuer
- func Package(v string) Valuer
- func RequestId(f func(c context.Context) string) Valuer
- func TraceId(f func(c context.Context) string) Valuer
- func Type(v string) Valuer
- func Unit(v string) Valuer
Constants ¶
const ( DebugLevel = zap.DebugLevel InfoLevel = zap.InfoLevel WarnLevel = zap.WarnLevel ErrorLevel = zap.ErrorLevel DPanicLevel = zap.DPanicLevel PanicLevel = zap.PanicLevel FatalLevel = zap.FatalLevel )
Variables ¶
var ( Skip = zap.Skip Binary = zap.Binary Bool = zap.Bool Boolp = zap.Boolp ByteString = zap.ByteString Complex128 = zap.Complex128 Complex128p = zap.Complex128p Complex64 = zap.Complex64 Complex64p = zap.Complex64p Float64 = zap.Float64 Float64p = zap.Float64p Float32 = zap.Float32 Float32p = zap.Float32p Int = zap.Int Intp = zap.Intp Int64 = zap.Int64 Int64p = zap.Int64p Int32 = zap.Int32 Int32p = zap.Int32p Int16 = zap.Int16 Int16p = zap.Int16p Int8 = zap.Int8 Int8p = zap.Int8p String = zap.String Stringp = zap.Stringp Uint = zap.Uint Uintp = zap.Uintp Uint64 = zap.Uint64 Uint64p = zap.Uint64p Uint32 = zap.Uint32 Uint32p = zap.Uint32p Uint16 = zap.Uint16 Uint16p = zap.Uint16p Uint8 = zap.Uint8 Uint8p = zap.Uint8p Uintptr = zap.Uintptr Uintptrp = zap.Uintptrp Reflect = zap.Reflect Namespace = zap.Namespace Stringer = zap.Stringer Time = zap.Time Timep = zap.Timep Stack = zap.Stack StackSkip = zap.StackSkip Duration = zap.Duration Durationp = zap.Durationp Any = zap.Any )
Functions ¶
func DPanic ¶
func DPanic(args ...any)
DPanic uses fmt.Sprint to construct and log a message. In development, the logger then panics. (See DPanicLevel for details.)
func DPanicf ¶
DPanicf uses fmt.Sprintf to log a templated message. In development, the logger then panics. (See DPanicLevel for details.)
func DPanicw ¶
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 Debugw ¶
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 Errorw ¶
Errorw logs a message with some additional context. The variadic key-value pairs are treated as they are in With.
func Fatal ¶
func Fatal(args ...any)
Fatal uses fmt.Sprint to construct and log a message, then calls os.Exit.
func Fatalw ¶
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 Infow ¶
Infow logs a message with some additional context. The variadic key-value pairs are treated as they are in With.
func Panic ¶
func Panic(args ...any)
Panic uses fmt.Sprint to construct and log a message, then panics.
func Panicw ¶
Panicw logs a message with some additional context, then panics. The variadic key-value pairs are treated as they are in With.
func SetLevelWithText ¶
SetLevelWithText alters the logging level. ParseAtomicLevel set the logging level based on a lowercase or all-caps ASCII representation of the log level. If the provided ASCII representation is invalid an error is returned.
Types ¶
type Config ¶
type Config struct { // Level 日志等级, debug,info,warn,error,dpanic,panic,fatal, 默认warn Level string `yaml:"level" json:"level"` // Format: 编码格式: json,console 默认json Format string `yaml:"format" json:"format"` // Adapter 输出适配器, file,console,multi,custom,file-custom,console-custom,multi-custom 默认 console Adapter string `yaml:"adapter" json:"adapter"` // Stack 是否使能栈调试输出, 默认false Stack bool `yaml:"stack" json:"stack"` // AddCaller add caller AddCaller bool `yaml:"addCaller" json:"addCaller"` // CallerSkip call skip if AddCaller enabled CallerSkip int `yaml:"callerSkip" json:"callerSkip"` // Path 日志保存路径, 默认 empty, 即当前路径 Path string `yaml:"path" json:"path"` // Writer 输出 // 当 adapter=custom使用,如果为writer为空,将使用os.Stdout Writer []io.Writer `yaml:"-" json:"-"` // see https://github.com/natefinch/lumberjack // lumberjack.Log // Filename 空字符使用默认, 默认<processname>-lumberjack.log Filename string `yaml:"filename" json:"filename"` // MaxSize 每个日志文件最大尺寸(MB), 默认100MB MaxSize int `yaml:"maxSize" json:"maxSize"` // MaxAge 日志文件保存天数, 默认0 不删除 MaxAge int `yaml:"maxAge" json:"maxAge"` // MaxBackups 日志文件保存备份数, 默认0 都保存 MaxBackups int `yaml:"maxBackups" json:"maxBackups"` // LocalTime 是否格式化时间戳, 默认UTC时间 LocalTime bool `yaml:"localTime" json:"localTime"` // Compress 是否使用gzip压缩文件, 采用默认不压缩 Compress bool `yaml:"compress" json:"compress"` }
Config 日志配置
type Log ¶
type Log struct {
// contains filtered or unexported fields
}
Log wrap zap logger
func NewLoggerWith ¶
func NewLoggerWith(logger *zap.Logger, lv zap.AtomicLevel) *Log
NewLoggerWith new logger with zap logger and atomic level
func SetDefaultValuer ¶
SetDefaultValuer set default field function, which hold always until you call WithContext.
func With ¶
With adds a variadic number of fields to the logging context. It accepts a mix of strongly-typed Field objects and loosely-typed key-value pairs. When processing pairs, the first element of the pair is used as the field key and the second as the field value.
For example,
sugaredLogger.With( "hello", "world", "failure", errors.New("oh no"), "count", 42, "user", User{Name: "alice"}, )
is the equivalent of
unsugared.With( String("hello", "world"), String("failure", "oh no"), Stack(), Int("count", 42), Object("user", User{Name: "alice"}), )
Note that the keys in key-value pairs should be strings. In development, passing a non-string key panics. In production, the logger is more forgiving: a separate error is logged, but the key-value pair is skipped and execution continues. Passing an orphaned key triggers similar behavior: panics in development and errors in production.
func WithContext ¶
WithContext return log with inject context.
func WithNewValuer ¶
WithNewValuer return log with new Valuer function without default Valuer.
func (*Log) DPanic ¶
DPanic uses fmt.Sprint to construct and log a message. In development, the logger then panics. (See DPanicLevel for details.)
func (*Log) DPanicf ¶
DPanicf uses fmt.Sprintf to log a templated message. In development, the logger then panics. (See DPanicLevel for details.)
func (*Log) DPanicw ¶
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 (*Log) Debugw ¶
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 (*Log) Errorw ¶
Errorw logs a message with some additional context. The variadic key-value pairs are treated as they are in With.
func (*Log) Fatalw ¶
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 (*Log) Infow ¶
Infow logs a message with some additional context. The variadic key-value pairs are treated as they are in With.
func (*Log) Panicw ¶
Panicw logs a message with some additional context, then panics. The variadic key-value pairs are treated as they are in With.
func (*Log) SetDefaultValuer ¶
SetDefaultValuer set default Valuer function, which hold always until you call WithContext.
func (*Log) SetLevelWithText ¶
SetLevelWithText alters the logging level. ParseAtomicLevel set the logging level based on a lowercase or all-caps ASCII representation of the log level. If the provided ASCII representation is invalid an error is returned. see zapcore.Level
func (*Log) Sugar ¶
func (l *Log) Sugar() *zap.SugaredLogger
Sugar wraps the Logger to provide a more ergonomic, but slightly slower, API. Sugaring a Logger is quite inexpensive, so it's reasonable for a single application to use both Loggers and SugaredLoggers, converting between them on the boundaries of performance-sensitive code.
func (*Log) Warnw ¶
Warnw logs a message with some additional context. The variadic key-value pairs are treated as they are in With.
func (*Log) 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 (*Log) WithContext ¶
WithContext return log with inject context.
func (*Log) WithNewValuer ¶
WithNewValuer return log with new Valuer function without default Valuer.
func (*Log) WithValuer ¶
WithValuer with Valuer function.
type Option ¶
type Option func(c *Config)
Option An Option configures a Log.
func WithAdapter ¶
WithAdapter with adapter file,console,multi,custom,file-custom,console-custom,multi-custom writer: 当 adapter=custom使用,如果为writer为空,将使用os.Stdout 默认 console
func WithAddCaller ¶
WithAddCaller with AddCaller 是否输出调用 filename 和 line number
func WithEnableCompress ¶
func WithEnableCompress() Option
WithEnableCompress with compress 是否使用gzip压缩文件, 采用默认不压缩
func WithEnableLocalTime ¶
func WithEnableLocalTime() Option
WithEnableLocalTime with local time 是否格式化时间戳, 默认UTC时间
func WithFilename ¶
WithFilename with filename 空字符使用默认, 默认<processname>-lumberjack.log
func WithMaxBackups ¶
WithMaxBackups with max backup 日志文件保存备份数, 默认0 都保存
func WithMaxSize ¶
WithMaxSize with max size 每个日志文件最大尺寸(MB), 默认100MB
type Valuer ¶
Valuer is returns a log value.
func FromComplex128 ¶
func FromComplex128(key string, vf func(context.Context) complex128) Valuer
func FromComplex128p ¶
func FromComplex128p(key string, vf func(context.Context) *complex128) Valuer
func FromNamespace ¶
func FromStackSkip ¶
func ImmutBinary ¶
func ImmutBoolp ¶
func ImmutByteString ¶
func ImmutComplex128 ¶
func ImmutComplex128(key string, v complex128) Valuer
func ImmutComplex128p ¶
func ImmutComplex128p(key string, v *complex128) Valuer