log

package module
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: MIT Imports: 14 Imported by: 2

README

log

zap logger with lumberjack

GoDoc Go.Dev reference codecov Tests Go Report Card Licence Tag

Features

Usage

Installation

Use go get.

    go get github.com/things-go/log

Then import the package into your own code.

    import "github.com/things-go/log"
Example

License

This project is under MIT License. See the LICENSE file for the full license text.

Documentation

Index

Constants

View Source
const (
	DebugLevel  = zap.DebugLevel
	InfoLevel   = zap.InfoLevel
	WarnLevel   = zap.WarnLevel
	ErrorLevel  = zap.ErrorLevel
	DPanicLevel = zap.DPanicLevel
	PanicLevel  = zap.PanicLevel
	FatalLevel  = zap.FatalLevel
)
View Source
const (
	AdapterConsole       = "console"        // console
	AdapterFile          = "file"           // file
	AdapterMulti         = "multi"          // file and console
	AdapterCustom        = "custom"         // custom io.Writer
	AdapterConsoleCustom = "console-custom" // console and custom io.Writer
	AdapterFileCustom    = "file-custom"    // file and custom io.Writer
	AdapterMultiCustom   = "multi-custom"   // file, console and custom io.Writer
)

adapter defined

View Source
const (
	FormatJson    = "json"
	FormatConsole = "console"
)

format defined

Variables

This section is empty.

Functions

func DPanic

func DPanic(args ...any)

func DPanicContext added in v0.0.4

func DPanicContext(ctx context.Context, args ...any)

func DPanicf

func DPanicf(template string, args ...any)

func DPanicfContext added in v0.0.4

func DPanicfContext(ctx context.Context, template string, args ...any)

func DPanicw

func DPanicw(msg string, keysAndValues ...any)

func DPanicwContext added in v0.0.4

func DPanicwContext(ctx context.Context, msg string, keysAndValues ...any)

func DPanicx added in v0.0.4

func DPanicx(msg string, fields ...Field)

func DPanicxContext added in v0.0.4

func DPanicxContext(ctx context.Context, msg string, fields ...Field)

func Debug

func Debug(args ...any)

func DebugContext added in v0.0.4

func DebugContext(ctx context.Context, args ...any)

func Debugf

func Debugf(template string, args ...any)

func DebugfContext added in v0.0.4

func DebugfContext(ctx context.Context, template string, args ...any)

func Debugw

func Debugw(msg string, keysAndValues ...any)

func DebugwContext added in v0.0.4

func DebugwContext(ctx context.Context, msg string, keysAndValues ...any)

func Debugx added in v0.0.4

func Debugx(msg string, fields ...Field)

func DebugxContext added in v0.0.4

func DebugxContext(ctx context.Context, msg string, fields ...Field)

func Enabled

func Enabled(lvl Level) bool

Enabled returns true if the given level is at or above this level.

func Error

func Error(args ...any)

func ErrorContext added in v0.0.4

func ErrorContext(ctx context.Context, args ...any)

func Errorf

func Errorf(template string, args ...any)

func ErrorfContext added in v0.0.4

func ErrorfContext(ctx context.Context, template string, args ...any)

func Errorw

func Errorw(msg string, keysAndValues ...any)

func ErrorwContext added in v0.0.4

func ErrorwContext(ctx context.Context, msg string, keysAndValues ...any)

func Errorx added in v0.0.4

func Errorx(msg string, fields ...Field)

func ErrorxContext added in v0.0.4

func ErrorxContext(ctx context.Context, msg string, fields ...Field)

func Fatal

func Fatal(args ...any)

func FatalContext added in v0.0.4

func FatalContext(ctx context.Context, args ...any)

func Fatalf

func Fatalf(template string, args ...any)

func FatalfContext added in v0.0.4

func FatalfContext(ctx context.Context, template string, args ...any)

func Fatalw

func Fatalw(msg string, keysAndValues ...any)

func FatalwContext added in v0.0.4

func FatalwContext(ctx context.Context, msg string, keysAndValues ...any)

func Fatalx added in v0.0.4

func Fatalx(msg string, fields ...Field)

func FatalxContext added in v0.0.4

func FatalxContext(ctx context.Context, msg string, fields ...Field)

func Info

func Info(args ...any)

func InfoContext added in v0.0.4

func InfoContext(ctx context.Context, args ...any)

func Infof

func Infof(template string, args ...any)

func InfofContext added in v0.0.4

func InfofContext(ctx context.Context, template string, args ...any)

func Infow

func Infow(msg string, keysAndValues ...any)

func InfowContext added in v0.0.4

func InfowContext(ctx context.Context, msg string, keysAndValues ...any)

func Infox added in v0.0.4

func Infox(msg string, fields ...Field)

func InfoxContext added in v0.0.4

func InfoxContext(ctx context.Context, msg string, fields ...Field)

func Logger

func Logger() *zap.Logger

Logger return internal logger

func New

func New(opts ...Option) (*zap.Logger, zap.AtomicLevel)

New constructs a new Log

func Panic

func Panic(args ...any)

func PanicContext added in v0.0.4

func PanicContext(ctx context.Context, args ...any)

func Panicf

func Panicf(template string, args ...any)

func PanicfContext added in v0.0.4

func PanicfContext(ctx context.Context, template string, args ...any)

func Panicw

func Panicw(msg string, keysAndValues ...any)

func PanicwContext added in v0.0.4

func PanicwContext(ctx context.Context, msg string, keysAndValues ...any)

func Panicx added in v0.0.4

func Panicx(msg string, fields ...Field)

func PanicxContext added in v0.0.4

func PanicxContext(ctx context.Context, msg string, fields ...Field)

func ReplaceGlobals

func ReplaceGlobals(logger *Log)

ReplaceGlobals replaces the global Log only once.

func SetLevelWithText

func SetLevelWithText(text string) error

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.

func Sugar

func 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 Sync

func Sync() error

Sync flushes any buffered log entries.

func V

func V(lvl int) bool

V returns true if the given level is at or above this level. same as Enabled

func Warn

func Warn(args ...any)

func WarnContext added in v0.0.4

func WarnContext(ctx context.Context, args ...any)

func Warnf

func Warnf(template string, args ...any)

func WarnfContext added in v0.0.4

func WarnfContext(ctx context.Context, template string, args ...any)

func Warnw

func Warnw(msg string, keysAndValues ...any)

func WarnwContext added in v0.0.4

func WarnwContext(ctx context.Context, msg string, keysAndValues ...any)

func Warnx added in v0.0.4

func Warnx(msg string, fields ...Field)

func WarnxContext added in v0.0.4

func WarnxContext(ctx context.Context, msg string, fields ...Field)

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"`
	// 编码器类型, 默认: LowercaseLevelEncoder
	// LowercaseLevelEncoder: 小写编码器
	// LowercaseColorLevelEncoder: 小写编码器带颜色
	// CapitalLevelEncoder: 大写编码器
	// CapitalColorLevelEncoder: 大写编码器带颜色
	EncodeLevel string `yaml:"encodeLevel" json:"encodeLevel"`
	// 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:"-"`
	// EncoderConfig 如果配置该项,则 EncodeLevel 将被覆盖
	EncoderConfig *zapcore.EncoderConfig `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 Field

type Field = zap.Field

func Any

func Any(key string, val any) Field

func Binary

func Binary(key string, val []byte) Field

func Bool

func Bool(key string, val bool) Field

func Boolp

func Boolp(key string, val *bool) Field

func ByteString

func ByteString(key string, val []byte) Field

func Complex128

func Complex128(key string, val complex128) Field

func Complex128p

func Complex128p(key string, val *complex128) Field

func Complex64

func Complex64(key string, val complex64) Field

func Complex64p

func Complex64p(key string, val *complex64) Field

func Dict added in v0.0.4

func Dict(key string, val ...Field) Field

func Duration

func Duration(key string, val time.Duration) Field

func Durationp

func Durationp(key string, val *time.Duration) Field

func Err added in v0.0.4

func Err(val error) Field

func Errors added in v0.0.4

func Errors(key string, val []error) Field

func Float32

func Float32(key string, val float32) Field

func Float32p

func Float32p(key string, val *float32) Field

func Float64

func Float64(key string, val float64) Field

func Float64p

func Float64p(key string, val *float64) Field

func Inline added in v0.0.4

func Inline(val ObjectMarshaler) Field

func Int

func Int(key string, val int) Field

func Int16

func Int16(key string, val int16) Field

func Int16p

func Int16p(key string, val *int16) Field

func Int32

func Int32(key string, val int32) Field

func Int32p

func Int32p(key string, val *int32) Field

func Int64

func Int64(key string, val int64) Field

func Int64p

func Int64p(key string, val *int64) Field

func Int8

func Int8(key string, val int8) Field

func Int8p

func Int8p(key string, val *int8) Field

func Intp

func Intp(key string, val *int) Field

func NamedError added in v0.0.4

func NamedError(key string, val error) Field

func Namespace

func Namespace(key string) Field

func Object added in v0.0.4

func Object(key string, val ObjectMarshaler) Field

func Reflect

func Reflect(key string, val any) Field

func Skip

func Skip() Field

func Stack

func Stack(key string) Field

func StackSkip

func StackSkip(key string, skip int) Field

func String

func String(key string, val string) Field

func Stringer

func Stringer(key string, val fmt.Stringer) Field

func Stringp

func Stringp(key string, val *string) Field

func Time

func Time(key string, val time.Time) Field

func Timep

func Timep(key string, val *time.Time) Field

func Uint

func Uint(key string, val uint) Field

func Uint16

func Uint16(key string, val uint16) Field

func Uint16p

func Uint16p(key string, val *uint16) Field

func Uint32

func Uint32(key string, val uint32) Field

func Uint32p

func Uint32p(key string, val *uint32) Field

func Uint64

func Uint64(key string, val uint64) Field

func Uint64p

func Uint64p(key string, val *uint64) Field

func Uint8

func Uint8(key string, val uint8) Field

func Uint8p

func Uint8p(key string, val *uint8) Field

func Uintp

func Uintp(key string, val *uint) Field

func Uintptr

func Uintptr(key string, val uintptr) Field

func Uintptrp

func Uintptrp(key string, val *uintptr) Field

type Level

type Level = zapcore.Level

func GetLevel

func GetLevel() Level

GetLevel returns the minimum enabled log level.

type Log

type Log struct {
	// contains filtered or unexported fields
}

Log wrap zap logger - methods named after the log level or ending in "Context" for log.Print-style logging - methods ending in "w" or "wContext" for loosely-typed structured logging - methods ending in "f" or "fContext" for log.Printf-style logging - methods ending in "x" or "xContext" for structured logging

func Named

func Named(name string) *Log

Named adds a sub-scope to the logger's name. See Log.Named for details.

func NewLogger

func NewLogger(opts ...Option) *Log

NewLogger new logger

func NewLoggerWith

func NewLoggerWith(logger *zap.Logger, lv zap.AtomicLevel) *Log

NewLoggerWith new logger with zap logger and atomic level

func SetDefaultValuer

func SetDefaultValuer(vs ...Valuer) *Log

SetDefaultValuer set default field function, which hold always until you call WithContext. suggest

func SetLevel

func SetLevel(lv zapcore.Level) *Log

SetLevel alters the logging level.

func With

func With(fields ...Field) *Log

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 deprecated

func WithContext(ctx context.Context) *Log

WithContext return log with inject context.

Deprecated: Use XXXContext to inject context. such as DebugContext.

func WithNewValuer

func WithNewValuer(fs ...Valuer) *Log

WithNewValuer return log with new Valuer function without default Valuer.

func WithValuer

func WithValuer(vs ...Valuer) *Log

WithValuer with field function.

func (*Log) DPanic

func (l *Log) DPanic(args ...any)

DPanic see DPanicContext

func (*Log) DPanicContext added in v0.0.4

func (l *Log) DPanicContext(ctx context.Context, args ...any)

DPanicContext uses fmt.Sprint to construct and log a message. In development, the logger then panics. (see DPanicLevel for details.)

func (*Log) DPanicf

func (l *Log) DPanicf(template string, args ...any)

DPanicf see DPanicfContext

func (*Log) DPanicfContext added in v0.0.4

func (l *Log) DPanicfContext(ctx context.Context, template string, args ...any)

DPanicfContext uses fmt.Sprintf to log a templated message. In development, the logger then panics. (see DPanicLevel for details.)

func (*Log) DPanicw

func (l *Log) DPanicw(msg string, keysAndValues ...any)

DPanicw see DPanicwContext

func (*Log) DPanicwContext added in v0.0.4

func (l *Log) DPanicwContext(ctx context.Context, msg string, keysAndValues ...any)

DPanicwContext logs a message with some additional context. In development, the logger then panics. (see DPanicLevel for details.) The variadic key-value pairs or Field are treated as they are in With.

func (*Log) DPanicx added in v0.0.4

func (l *Log) DPanicx(msg string, fields ...Field)

DPanic see DPanicContext

func (*Log) DPanicxContext added in v0.0.4

func (l *Log) DPanicxContext(ctx context.Context, msg string, fields ...Field)

DPanicContext uses fmt.Sprint to construct and log a message. In development, the logger then panics. (see DPanicLevel for details.)

func (*Log) Debug

func (l *Log) Debug(args ...any)

Debug (see DebugContext)

func (*Log) DebugContext added in v0.0.4

func (l *Log) DebugContext(ctx context.Context, args ...any)

DebugContext uses fmt.Sprint to construct and log a message.

func (*Log) Debugf

func (l *Log) Debugf(template string, args ...any)

Debugf see DebugfContext

func (*Log) DebugfContext added in v0.0.4

func (l *Log) DebugfContext(ctx context.Context, template string, args ...any)

DebugfContext uses fmt.Sprintf to log a templated message.

func (*Log) Debugw

func (l *Log) Debugw(msg string, keysAndValues ...any)

Debugw see DebugwContext

func (*Log) DebugwContext added in v0.0.4

func (l *Log) DebugwContext(ctx context.Context, msg string, keysAndValues ...any)

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

When debug-level logging is disabled, this is much faster than

s.With(fields).Debug(msg)

func (*Log) Debugx added in v0.0.4

func (l *Log) Debugx(msg string, fields ...Field)

Debug (see DebugContext)

func (*Log) DebugxContext added in v0.0.4

func (l *Log) DebugxContext(ctx context.Context, msg string, fields ...Field)

DebugContext uses fmt.Sprint to construct and log a message.

func (*Log) Enabled

func (l *Log) Enabled(lvl Level) bool

Enabled returns true if the given level is at or above this level.

func (*Log) Error

func (l *Log) Error(args ...any)

Error see ErrorContext

func (*Log) ErrorContext added in v0.0.4

func (l *Log) ErrorContext(ctx context.Context, args ...any)

ErrorContext uses fmt.Sprint to construct and log a message.

func (*Log) Errorf

func (l *Log) Errorf(template string, args ...any)

Errorf see ErrorfContext

func (*Log) ErrorfContext added in v0.0.4

func (l *Log) ErrorfContext(ctx context.Context, template string, args ...any)

ErrorfContext uses fmt.Sprintf to log a templated message.

func (*Log) Errorw

func (l *Log) Errorw(msg string, keysAndValues ...any)

Errorw see ErrorwContext

func (*Log) ErrorwContext added in v0.0.4

func (l *Log) ErrorwContext(ctx context.Context, msg string, keysAndValues ...any)

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

func (*Log) Errorx added in v0.0.4

func (l *Log) Errorx(msg string, fields ...Field)

Error see ErrorContext

func (*Log) ErrorxContext added in v0.0.4

func (l *Log) ErrorxContext(ctx context.Context, msg string, fields ...Field)

ErrorContext uses fmt.Sprint to construct and log a message.

func (*Log) Fatal

func (l *Log) Fatal(args ...any)

Fatal see FatalContext

func (*Log) FatalContext added in v0.0.4

func (l *Log) FatalContext(ctx context.Context, args ...any)

FatalContext uses fmt.Sprint to construct and log a message, then calls os.Exit.

func (*Log) Fatalf

func (l *Log) Fatalf(template string, args ...any)

Fatalf see FatalfContext

func (*Log) FatalfContext added in v0.0.4

func (l *Log) FatalfContext(ctx context.Context, template string, args ...any)

Fatalf uses fmt.Sprintf to log a templated message, then calls os.Exit.

func (*Log) Fatalw

func (l *Log) Fatalw(msg string, keysAndValues ...any)

func (*Log) FatalwContext added in v0.0.4

func (l *Log) FatalwContext(ctx context.Context, msg string, keysAndValues ...any)

FatalwContext logs a message with some additional context, then calls os.Exit. The variadic key-value pairs or Field are treated as they are in With.

func (*Log) Fatalx added in v0.0.4

func (l *Log) Fatalx(msg string, fields ...Field)

Fatal see FatalContext

func (*Log) FatalxContext added in v0.0.4

func (l *Log) FatalxContext(ctx context.Context, msg string, fields ...Field)

FatalContext uses fmt.Sprint to construct and log a message, then calls os.Exit.

func (*Log) GetLevel

func (l *Log) GetLevel() Level

GetLevel returns the minimum enabled log level.

func (*Log) Info

func (l *Log) Info(args ...any)

Info see InfoContext

func (*Log) InfoContext added in v0.0.4

func (l *Log) InfoContext(ctx context.Context, args ...any)

InfoContext uses fmt.Sprint to construct and log a message.

func (*Log) Infof

func (l *Log) Infof(template string, args ...any)

Infof see InfofContext

func (*Log) InfofContext added in v0.0.4

func (l *Log) InfofContext(ctx context.Context, template string, args ...any)

InfofContext uses fmt.Sprintf to log a templated message.

func (*Log) Infow

func (l *Log) Infow(msg string, keysAndValues ...any)

Infow see InfowContext

func (*Log) InfowContext added in v0.0.4

func (l *Log) InfowContext(ctx context.Context, msg string, keysAndValues ...any)

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

func (*Log) Infox added in v0.0.4

func (l *Log) Infox(msg string, fields ...Field)

Info see InfoContext

func (*Log) InfoxContext added in v0.0.4

func (l *Log) InfoxContext(ctx context.Context, msg string, fields ...Field)

InfoContext uses fmt.Sprint to construct and log a message.

func (*Log) Log added in v0.0.4

func (l *Log) Log(ctx context.Context, level Level, args ...any)

func (*Log) Logf added in v0.0.4

func (l *Log) Logf(ctx context.Context, level Level, template string, args ...any)

func (*Log) Logger

func (l *Log) Logger() *zap.Logger

Logger return internal logger

func (*Log) Logw added in v0.0.4

func (l *Log) Logw(ctx context.Context, level Level, msg string, keysAndValues ...any)

func (*Log) Logx added in v0.0.4

func (l *Log) Logx(ctx context.Context, level Level, msg string, fields ...Field)

func (*Log) Named

func (l *Log) Named(name string) *Log

Named adds a sub-scope to the logger's name. See Log.Named for details.

func (*Log) Panic

func (l *Log) Panic(args ...any)

Panic see PanicContext

func (*Log) PanicContext added in v0.0.4

func (l *Log) PanicContext(ctx context.Context, args ...any)

PanicContext uses fmt.Sprint to to construct and log a message, then panics.

func (*Log) Panicf

func (l *Log) Panicf(template string, args ...any)

Panicf see PanicfContext

func (*Log) PanicfContext added in v0.0.4

func (l *Log) PanicfContext(ctx context.Context, template string, args ...any)

PanicfContext uses fmt.Sprintf to log a templated message, then panics.

func (*Log) Panicw

func (l *Log) Panicw(msg string, keysAndValues ...any)

Panicw see PanicwContext

func (*Log) PanicwContext added in v0.0.4

func (l *Log) PanicwContext(ctx context.Context, msg string, keysAndValues ...any)

PanicwContext logs a message with some additional context, then panics. The variadic key-value pairs or Field are treated as they are in With.

func (*Log) Panicx added in v0.0.4

func (l *Log) Panicx(msg string, fields ...Field)

Panic see PanicContext

func (*Log) PanicxContext added in v0.0.4

func (l *Log) PanicxContext(ctx context.Context, msg string, fields ...Field)

PanicContext uses fmt.Sprint to to construct and log a message, then panics.

func (*Log) SetDefaultValuer

func (l *Log) SetDefaultValuer(fs ...Valuer) *Log

SetDefaultValuer set default Valuer function, which hold always until you call WithContext.

func (*Log) SetLevel

func (l *Log) SetLevel(lv zapcore.Level) *Log

SetLevel alters the logging level.

func (*Log) SetLevelWithText

func (l *Log) SetLevelWithText(text string) error

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) Sync

func (l *Log) Sync() error

Sync flushes any buffered log entries.

func (*Log) V

func (l *Log) V(lvl int) bool

V returns true if the given level is at or above this level. same as Enabled

func (*Log) Warn

func (l *Log) Warn(args ...any)

Warn see WarnContext

func (*Log) WarnContext added in v0.0.4

func (l *Log) WarnContext(ctx context.Context, args ...any)

WarnContext uses fmt.Sprint to construct and log a message.

func (*Log) Warnf

func (l *Log) Warnf(template string, args ...any)

Warnf see WarnfContext

func (*Log) WarnfContext added in v0.0.4

func (l *Log) WarnfContext(ctx context.Context, template string, args ...any)

WarnfContext uses fmt.Sprintf to log a templated message.

func (*Log) Warnw

func (l *Log) Warnw(msg string, keysAndValues ...any)

Warnw see WarnwContext

func (*Log) WarnwContext added in v0.0.4

func (l *Log) WarnwContext(ctx context.Context, msg string, keysAndValues ...any)

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

func (*Log) Warnx added in v0.0.4

func (l *Log) Warnx(msg string, fields ...Field)

Warn see WarnContext

func (*Log) WarnxContext added in v0.0.4

func (l *Log) WarnxContext(ctx context.Context, msg string, fields ...Field)

WarnContext uses fmt.Sprint to construct and log a message.

func (*Log) With

func (l *Log) With(fields ...Field) *Log

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 deprecated

func (l *Log) WithContext(ctx context.Context) *Log

WithContext return log with inject context.

Deprecated: you should use XXXContext to inject context.

func (*Log) WithNewValuer

func (l *Log) WithNewValuer(fs ...Valuer) *Log

WithNewValuer return log with new Valuer function without default Valuer.

func (*Log) WithValuer

func (l *Log) WithValuer(fs ...Valuer) *Log

WithValuer with Valuer function.

type ObjectMarshaler added in v0.0.4

type ObjectMarshaler = zapcore.ObjectMarshaler

type Option

type Option func(c *Config)

Option An Option configures a Log.

func WithAdapter

func WithAdapter(adapter string, writer ...io.Writer) Option

WithAdapter with adapter file,console,multi,custom,file-custom,console-custom,multi-custom writer: 当 adapter=custom使用,如果为writer为空,将使用os.Stdout 默认 console

func WithAddCaller

func WithAddCaller(b bool) Option

WithAddCaller with AddCaller 是否输出调用 filename 和 line number

func WithCallerSkip

func WithCallerSkip(skip int) Option

WithCallerSkip when AddCaller enabled

func WithConfig

func WithConfig(cfg Config) Option

WithConfig with config

func WithEnableCompress

func WithEnableCompress() Option

WithEnableCompress with compress 是否使用gzip压缩文件, 采用默认不压缩

func WithEnableLocalTime

func WithEnableLocalTime() Option

WithEnableLocalTime with local time 是否格式化时间戳, 默认UTC时间

func WithEncodeLevel

func WithEncodeLevel(encodeLevel string) Option

WithEncodeLevel with EncodeLevel LowercaseLevelEncoder: 小写编码器 LowercaseColorLevelEncoder: 小写编码器带颜色 CapitalLevelEncoder: 大写编码器 CapitalColorLevelEncoder: 大写编码器带颜色 默认: LowercaseLevelEncoder

func WithEncoderConfig

func WithEncoderConfig(encoderConfig *zapcore.EncoderConfig) Option

EncoderConfig 如果配置该项,则 EncodeLevel 将被覆盖

func WithFilename

func WithFilename(filename string) Option

WithFilename with filename 空字符使用默认, 默认<processname>-lumberjack.log

func WithFormat

func WithFormat(format string) Option

WithFormat with format json,console 默认json

func WithLevel

func WithLevel(level string) Option

WithLevel with level debug,info,warn,error,dpanic,panic,fatal 默认warn

func WithMaxAge

func WithMaxAge(maxAge int) Option

WithMaxAge with max age 日志文件保存天数, 默认0 不删除

func WithMaxBackups

func WithMaxBackups(maxBackups int) Option

WithMaxBackups with max backup 日志文件保存备份数, 默认0 都保存

func WithMaxSize

func WithMaxSize(maxSize int) Option

WithMaxSize with max size 每个日志文件最大尺寸(MB), 默认100MB

func WithPath

func WithPath(path string) Option

WithPath with path 日志保存路径, 默认 empty, 即当前路径

func WithStack

func WithStack(stack bool) Option

WithStack with stack Stack 是否使能栈调试输出, 默认false

type Valuer

type Valuer func(ctx context.Context) Field

Valuer is returns a log value.

func App

func App(v string) Valuer

func Caller

func Caller(depth int) Valuer

Caller returns a Valuer that returns a pkg/file:line description of the caller.

func Component

func Component(v string) Valuer

func File

func File(depth int) Valuer

File returns a Valuer that returns a pkg/file:line description of the caller.

func FromAny

func FromAny(key string, vf func(context.Context) any) Valuer

func FromBinary

func FromBinary(key string, vf func(context.Context) []byte) Valuer

func FromBool

func FromBool(key string, vf func(context.Context) bool) Valuer

func FromBoolp

func FromBoolp(key string, vf func(context.Context) *bool) Valuer

func FromByteString

func FromByteString(key string, vf func(context.Context) []byte) Valuer

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 FromComplex64

func FromComplex64(key string, vf func(context.Context) complex64) Valuer

func FromComplex64p

func FromComplex64p(key string, vf func(context.Context) *complex64) Valuer

func FromDuration

func FromDuration(key string, vf func(context.Context) time.Duration) Valuer

func FromDurationp

func FromDurationp(key string, vf func(context.Context) *time.Duration) Valuer

func FromErr added in v0.0.5

func FromErr(vf func(context.Context) error) Valuer

func FromErrors added in v0.0.5

func FromErrors(key string, vf func(context.Context) []error) Valuer

func FromFloat32

func FromFloat32(key string, vf func(context.Context) float32) Valuer

func FromFloat32p

func FromFloat32p(key string, vf func(context.Context) *float32) Valuer

func FromFloat64

func FromFloat64(key string, vf func(context.Context) float64) Valuer

func FromFloat64p

func FromFloat64p(key string, vf func(context.Context) *float64) Valuer

func FromInt

func FromInt(key string, vf func(context.Context) int) Valuer

func FromInt16

func FromInt16(key string, vf func(context.Context) int16) Valuer

func FromInt16p

func FromInt16p(key string, vf func(context.Context) *int16) Valuer

func FromInt32

func FromInt32(key string, vf func(context.Context) int32) Valuer

func FromInt32p

func FromInt32p(key string, vf func(context.Context) *int32) Valuer

func FromInt64

func FromInt64(key string, vf func(context.Context) int64) Valuer

func FromInt64p

func FromInt64p(key string, vf func(context.Context) *int64) Valuer

func FromInt8

func FromInt8(key string, vf func(context.Context) int8) Valuer

func FromInt8p

func FromInt8p(key string, vf func(context.Context) *int8) Valuer

func FromIntp

func FromIntp(key string, vf func(context.Context) *int) Valuer

func FromNamedError added in v0.0.5

func FromNamedError(key string, vf func(context.Context) error) Valuer

func FromReflect

func FromReflect(key string, vf func(context.Context) any) Valuer

func FromString

func FromString(key string, vf func(context.Context) string) Valuer

func FromStringer

func FromStringer(key string, vf func(context.Context) fmt.Stringer) Valuer

func FromStringp

func FromStringp(key string, vf func(context.Context) *string) Valuer

func FromTime

func FromTime(key string, vf func(context.Context) time.Time) Valuer

func FromTimep

func FromTimep(key string, vf func(context.Context) *time.Time) Valuer

func FromUint

func FromUint(key string, vf func(context.Context) uint) Valuer

func FromUint16

func FromUint16(key string, vf func(context.Context) uint16) Valuer

func FromUint16p

func FromUint16p(key string, vf func(context.Context) *uint16) Valuer

func FromUint32

func FromUint32(key string, vf func(context.Context) uint32) Valuer

func FromUint32p

func FromUint32p(key string, vf func(context.Context) *uint32) Valuer

func FromUint64

func FromUint64(key string, vf func(context.Context) uint64) Valuer

func FromUint64p

func FromUint64p(key string, vf func(context.Context) *uint64) Valuer

func FromUint8

func FromUint8(key string, vf func(context.Context) uint8) Valuer

func FromUint8p

func FromUint8p(key string, vf func(context.Context) *uint8) Valuer

func FromUintp

func FromUintp(key string, vf func(context.Context) *uint) Valuer

func FromUintptr

func FromUintptr(key string, vf func(context.Context) uintptr) Valuer

func FromUintptrp

func FromUintptrp(key string, vf func(context.Context) *uintptr) Valuer

func ImmutAny

func ImmutAny(key string, v any) Valuer

func ImmutBinary

func ImmutBinary(key string, v []byte) Valuer

func ImmutBool

func ImmutBool(key string, v bool) Valuer

func ImmutBoolp

func ImmutBoolp(key string, v *bool) Valuer

func ImmutByteString

func ImmutByteString(key string, v []byte) Valuer

func ImmutComplex128

func ImmutComplex128(key string, v complex128) Valuer

func ImmutComplex128p

func ImmutComplex128p(key string, v *complex128) Valuer

func ImmutComplex64

func ImmutComplex64(key string, v complex64) Valuer

func ImmutComplex64p

func ImmutComplex64p(key string, v *complex64) Valuer

func ImmutDict added in v0.0.4

func ImmutDict(key string, val ...Field) Valuer

func ImmutDuration

func ImmutDuration(key string, v time.Duration) Valuer

func ImmutDurationp

func ImmutDurationp(key string, v *time.Duration) Valuer

func ImmutErr added in v0.0.4

func ImmutErr(val error) Valuer

func ImmutErrors added in v0.0.4

func ImmutErrors(key string, val []error) Valuer

func ImmutFloat32

func ImmutFloat32(key string, v float32) Valuer

func ImmutFloat32p

func ImmutFloat32p(key string, v *float32) Valuer

func ImmutFloat64

func ImmutFloat64(key string, v float64) Valuer

func ImmutFloat64p

func ImmutFloat64p(key string, v *float64) Valuer

func ImmutInline added in v0.0.4

func ImmutInline(val ObjectMarshaler) Valuer

func ImmutInt

func ImmutInt(key string, v int) Valuer

func ImmutInt16

func ImmutInt16(key string, v int16) Valuer

func ImmutInt16p

func ImmutInt16p(key string, v *int16) Valuer

func ImmutInt32

func ImmutInt32(key string, v int32) Valuer

func ImmutInt32p

func ImmutInt32p(key string, v *int32) Valuer

func ImmutInt64

func ImmutInt64(key string, v int64) Valuer

func ImmutInt64p

func ImmutInt64p(key string, v *int64) Valuer

func ImmutInt8

func ImmutInt8(key string, v int8) Valuer

func ImmutInt8p

func ImmutInt8p(key string, v *int8) Valuer

func ImmutIntp

func ImmutIntp(key string, v *int) Valuer

func ImmutNamedError added in v0.0.4

func ImmutNamedError(key string, val error) Valuer

func ImmutNamespace added in v0.0.5

func ImmutNamespace(key string) Valuer

func ImmutObject added in v0.0.4

func ImmutObject(key string, val ObjectMarshaler) Valuer

func ImmutReflect

func ImmutReflect(key string, v any) Valuer

func ImmutStack added in v0.0.5

func ImmutStack(key string) Valuer

func ImmutStackSkip added in v0.0.5

func ImmutStackSkip(key string, skip int) Valuer

func ImmutString

func ImmutString(key string, v string) Valuer

func ImmutStringer

func ImmutStringer(key string, v fmt.Stringer) Valuer

func ImmutStringp

func ImmutStringp(key string, v *string) Valuer

func ImmutTime

func ImmutTime(key string, v time.Time) Valuer

func ImmutTimep

func ImmutTimep(key string, v *time.Time) Valuer

func ImmutUint

func ImmutUint(key string, v uint) Valuer

func ImmutUint16

func ImmutUint16(key string, v uint16) Valuer

func ImmutUint16p

func ImmutUint16p(key string, v *uint16) Valuer

func ImmutUint32

func ImmutUint32(key string, v uint32) Valuer

func ImmutUint32p

func ImmutUint32p(key string, v *uint32) Valuer

func ImmutUint64

func ImmutUint64(key string, v uint64) Valuer

func ImmutUint64p

func ImmutUint64p(key string, v *uint64) Valuer

func ImmutUint8

func ImmutUint8(key string, v uint8) Valuer

func ImmutUint8p

func ImmutUint8p(key string, v *uint8) Valuer

func ImmutUintp

func ImmutUintp(key string, v *uint) Valuer

func ImmutUintptr

func ImmutUintptr(key string, v uintptr) Valuer

func ImmutUintptrp

func ImmutUintptrp(key string, v *uintptr) Valuer

func Kind

func Kind(v string) Valuer

func Module

func Module(v string) Valuer

func Package

func Package(v string) Valuer

Package returns a Valuer that returns an immutable Valuer which key is pkg

func RequestId

func RequestId(f func(c context.Context) string) Valuer

func TraceId

func TraceId(f func(c context.Context) string) Valuer

func Type

func Type(v string) Valuer

func Unit

func Unit(v string) Valuer

Jump to

Keyboard shortcuts

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