logger

package module
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2025 License: MIT Imports: 13 Imported by: 4

README

logger

zap logger with lumberjack

Go.Dev reference codecov Tests Go Report Card License Tag

Features

Usage

example

Installation

Use go get.

    go get github.com/thinkgos/logger

Then import the package into your own code.

    import "github.com/thinkgos/logger"
示例
package main

import (
	"context"

	"github.com/thinkgos/logger"
)

type ctxKey struct{}

func ExampleHook(ctx context.Context) logger.Field {
	s, ok := ctx.Value(ctxKey{}).(string)
	if !ok {
		return logger.Skip()
	}
	return logger.String("ctx_key1", s)
}
func TmpHook(ctx context.Context) logger.Field {
	return logger.String("tmp_key1", "tmp_val1")
}

func main() {
	l := logger.NewLogger(
		logger.WithLevel(logger.DebugLevel.String()),
		logger.WithFormat(logger.FormatJson),
	).
		SetCallerLevel(logger.WarnLevel)
	logger.ReplaceGlobals(l)
	logger.SetDefaultHookFunc(ExampleHook)

	ctx := context.WithValue(context.Background(), ctxKey{}, "ctx_val1")

	logger.OnDebugContext(ctx).ExtendHookFunc(TmpHook).Msg("Debug1")
	logger.OnDebugContext(ctx).WithNewHook(logger.HookFunc(TmpHook)).Msg("Debug2")

	logger.SetLevel(logger.WarnLevel)
	logger.OnDebugContext(ctx).Msg("Debug3")

	err := logger.SetLevelWithText(logger.DebugLevel.String())
	_ = err
	logger.OnDebugContext(ctx).Msg("Debug4")

	// 这里改成warn等级方便测试
	logger.SetLevel(logger.WarnLevel)
	if logger.Enabled(logger.InfoLevel) { // 提前过滤
		logger.OnInfoContext(ctx).Msg("Info1") // 不执行
	}
	if logger.V(logger.InfoLevel) { // 提前过滤
		logger.OnInfoContext(ctx).Msg("Info2") // 不执行
	}
	logger.SetLevel(logger.DebugLevel)

	logger.Named("叫个名字").OnDebugContext(ctx).Msg(" Debug5")

	logger.OnInfoContext(ctx).
		With(
			logger.String("name", "jack"),
			logger.Int("age", 18),
		).
		Msg(" Debug6")

	logger.OnDebugContext(ctx).String("k1", "v1").String("k2", "v2").Print("Debug")
	logger.OnInfoContext(ctx).String("k1", "v1").String("k2", "v2").Printf("Info: %s", "info")
	logger.OnWarnContext(ctx).String("k1", "v1").String("k2", "v2").Msg("Warn")
	logger.OnInfoContext(ctx).String("k1", "v1").String("k2", "v2").Msg("Info")
	logger.OnErrorContext(ctx).String("k1", "v1").String("k2", "v2").Msg("Error")
	logger.OnDPanicContext(ctx).String("k1", "v1").String("k2", "v2").Msg("DPanic")
}

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
)

log level defined

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

View Source
const (
	EncodeLevelLowercase      = "LowercaseLevelEncoder"      // 小写编码器
	EncodeLevelLowercaseColor = "LowercaseColorLevelEncoder" // 小写编码器带颜色
	EncodeLevelCapital        = "CapitalLevelEncoder"        // 大写编码器
	EncodeLevelCapitalColor   = "CapitalColorLevelEncoder"   // 大写编码器带颜色
)

encode level defined

Variables

This section is empty.

Functions

func DPanic

func DPanic(args ...any)

func DPanicf

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

func Debug

func Debug(args ...any)

func Debugf

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

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 Errorf

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

func Fatal

func Fatal(args ...any)

func Fatalf

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

func Info

func Info(args ...any)

func Infof

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

func Logger

func Logger() *zap.Logger

Logger return internal logger

func Panic

func Panic(args ...any)

func Panicf

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

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 Level) bool

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

func Warn

func Warn(args ...any)

func Warnf

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

Types

type ArrayEncoder added in v1.0.0

type ArrayEncoder = zapcore.ArrayEncoder

type ArrayMarshaler added in v1.0.0

type ArrayMarshaler = zapcore.ArrayMarshaler

type AtomicLevel

type AtomicLevel = zap.AtomicLevel

func New

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

New constructs a new Log

func NewAtomicLevel

func NewAtomicLevel() AtomicLevel

NewAtomicLevel creates an AtomicLevel with InfoLevel and above logging enabled.

func NewAtomicLevelAt

func NewAtomicLevelAt(l Level) AtomicLevel

NewAtomicLevelAt is a convenience function that creates an AtomicLevel and then calls SetLevel with the given level.

func ParseAtomicLevel

func ParseAtomicLevel(text string) (AtomicLevel, error)

ParseAtomicLevel parses an AtomicLevel 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 UnderlyingCallerLevel

func UnderlyingCallerLevel() AtomicLevel

UnderlyingCallerLevel get underlying caller level.

type CallerCore

type CallerCore struct {
	Skip         int
	SkipPackages []string
	Caller       func(depth int, skipPackages ...string) Field
	// contains filtered or unexported fields
}

func NewCallerCore

func NewCallerCore() *CallerCore

func (*CallerCore) AddSkip

func (c *CallerCore) AddSkip(callerSkip int) *CallerCore

AddSkip add the number of callers skipped by caller annotation.

func (*CallerCore) AddSkipPackage

func (c *CallerCore) AddSkipPackage(vs ...string) *CallerCore

AddSkipPackage add the caller skip package.

func (*CallerCore) Enabled

func (c *CallerCore) Enabled(lvl Level) bool

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

func (*CallerCore) Level

func (c *CallerCore) Level() Level

Level returns the minimum enabled log level.

func (*CallerCore) SetLevel

func (c *CallerCore) SetLevel(lv Level) *CallerCore

SetLevel set the caller level.

func (*CallerCore) UnderlyingLevel

func (c *CallerCore) UnderlyingLevel() AtomicLevel

UnderlyingLevel get underlying level.

func (*CallerCore) UseExternalLevel

func (c *CallerCore) UseExternalLevel(l AtomicLevel) *CallerCore

UseExternalLevel use external level, which controller by user.

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"`
	// Writer 输出
	// 当adapter有附带custom时, 如果为writer为空, 将使用os.Stdout
	Writer []io.Writer `yaml:"-" json:"-"`
	// EncoderConfig 如果配置该项,则 EncodeLevel 将被覆盖
	EncoderConfig *zapcore.EncoderConfig `yaml:"-" json:"-"`
	// 文件配置, 仅Adapter有file时有效
	File LumberjackFile `yaml:"file" json:"file"`
}

Config 日志配置

type Event added in v1.0.0

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

Event represents a log event. It is instanced by one of the level method of Logger and finalized by the Msg, Print, Printf method.

func OnDPanic added in v1.0.0

func OnDPanic() *Event

OnDPanic starts a new message with DPanicLevel level.

You must call Msg on the returned event in order to send the event.

func OnDPanicContext added in v1.0.0

func OnDPanicContext(ctx context.Context) *Event

OnDPanicContext starts a new message with DPanicLevel level, and adds the Go Context to the *Event context.

You must call Msg on the returned event in order to send the event.

func OnDebug added in v1.0.0

func OnDebug() *Event

OnDebug starts a new message with DebugLevel level.

You must call Msg on the returned event in order to send the event.

func OnDebugContext added in v1.0.0

func OnDebugContext(ctx context.Context) *Event

Debug starts a new message with DebugLevel level, and adds the Go Context to the *Event context.

You must call Msg on the returned event in order to send the event.

func OnError added in v1.0.0

func OnError() *Event

OnError starts a new message with ErrorLevel level.

You must call Msg on the returned event in order to send the event.

func OnErrorContext added in v1.0.0

func OnErrorContext(ctx context.Context) *Event

OnErrorContext starts a new message with ErrorLevel level, and adds the Go Context to the *Event context.

You must call Msg on the returned event in order to send the event.

func OnFatal added in v1.0.0

func OnFatal() *Event

OnFatal starts a new message with FatalLevel level.

You must call Msg on the returned event in order to send the event.

func OnFatalContext added in v1.0.0

func OnFatalContext(ctx context.Context) *Event

OnFatalContext starts a new message with FatalLevel level, and adds the Go Context to the *Event context.

You must call Msg on the returned event in order to send the event.

func OnInfo added in v1.0.0

func OnInfo() *Event

OnInfo starts a new message with InfoLevel level.

You must call Msg on the returned event in order to send the event.

func OnInfoContext added in v1.0.0

func OnInfoContext(ctx context.Context) *Event

OnInfoContext starts a new message with InfoLevel level, and adds the Go Context to the *Event context.

You must call Msg on the returned event in order to send the event.

func OnLevel added in v1.0.0

func OnLevel(level Level) *Event

OnLevel starts a new message with customize level.

You must call Msg on the returned event in order to send the event.

func OnLevelContext added in v1.0.0

func OnLevelContext(ctx context.Context, level Level) *Event

OnLevelContext starts a new message with customize level, and adds the Go Context to the *Event context.

You must call Msg on the returned event in order to send the event.

func OnPanic added in v1.0.0

func OnPanic() *Event

OnPanic starts a new message with PanicLevel level.

You must call Msg on the returned event in order to send the event.

func OnPanicContext added in v1.0.0

func OnPanicContext(ctx context.Context) *Event

OnPanicContext starts a new message with PanicLevel level, and adds the Go Context to the *Event context.

You must call Msg on the returned event in order to send the event.

func OnWarn added in v1.0.0

func OnWarn() *Event

OnWarn starts a new message with WarnLevel level.

You must call Msg on the returned event in order to send the event.

func OnWarnContext added in v1.0.0

func OnWarnContext(ctx context.Context) *Event

OnWarnContext starts a new message with WarnLevel level, and adds the Go Context to the *Event context.

You must call Msg on the returned event in order to send the event.

func (*Event) Any added in v1.0.0

func (e *Event) Any(key string, v any) *Event

func (*Event) Array added in v1.0.0

func (e *Event) Array(key string, v ArrayMarshaler) *Event

func (*Event) Binary added in v1.0.0

func (e *Event) Binary(key string, v []byte) *Event

func (*Event) Bool added in v1.0.0

func (e *Event) Bool(key string, v bool) *Event

func (*Event) Boolp added in v1.0.0

func (e *Event) Boolp(key string, v *bool) *Event

func (*Event) ByteString added in v1.0.0

func (e *Event) ByteString(key string, v []byte) *Event

func (*Event) Caller added in v1.0.0

func (e *Event) Caller(depth int) *Event

func (*Event) CallerFile added in v1.0.0

func (e *Event) CallerFile(depth int) *Event

func (*Event) Complex128 added in v1.0.0

func (e *Event) Complex128(key string, v complex128) *Event

func (*Event) Complex128p added in v1.0.0

func (e *Event) Complex128p(key string, v *complex128) *Event

func (*Event) Complex64 added in v1.0.0

func (e *Event) Complex64(key string, v complex64) *Event

func (*Event) Complex64p added in v1.0.0

func (e *Event) Complex64p(key string, v *complex64) *Event

func (*Event) Configure added in v1.0.0

func (e *Event) Configure(f func(e *Event)) *Event

func (*Event) Dict added in v1.0.0

func (e *Event) Dict(key string, val ...Field) *Event

func (*Event) DoHook added in v1.0.0

func (e *Event) DoHook(hs ...Hook) *Event

DoHookFunc do hook immediately.

func (*Event) DoHookFunc added in v1.0.0

func (e *Event) DoHookFunc(hs ...HookFunc) *Event

DoHookFunc do hook func immediately.

func (*Event) Duration added in v1.0.0

func (e *Event) Duration(key string, v time.Duration) *Event

func (*Event) Durationp added in v1.0.0

func (e *Event) Durationp(key string, v *time.Duration) *Event

func (*Event) Error added in v1.0.0

func (e *Event) Error(val error) *Event

func (*Event) Errors added in v1.0.0

func (e *Event) Errors(key string, val []error) *Event

func (*Event) Float32 added in v1.0.0

func (e *Event) Float32(key string, v float32) *Event

func (*Event) Float32p added in v1.0.0

func (e *Event) Float32p(key string, v *float32) *Event

func (*Event) Float64 added in v1.0.0

func (e *Event) Float64(key string, v float64) *Event

func (*Event) Float64p added in v1.0.0

func (e *Event) Float64p(key string, v *float64) *Event

func (*Event) Inline added in v1.0.0

func (e *Event) Inline(val ObjectMarshaler) *Event

func (*Event) Int added in v1.0.0

func (e *Event) Int(key string, v int) *Event

func (*Event) Int16 added in v1.0.0

func (e *Event) Int16(key string, v int16) *Event

func (*Event) Int16p added in v1.0.0

func (e *Event) Int16p(key string, v *int16) *Event

func (*Event) Int32 added in v1.0.0

func (e *Event) Int32(key string, v int32) *Event

func (*Event) Int32p added in v1.0.0

func (e *Event) Int32p(key string, v *int32) *Event

func (*Event) Int64 added in v1.0.0

func (e *Event) Int64(key string, v int64) *Event

func (*Event) Int64p added in v1.0.0

func (e *Event) Int64p(key string, v *int64) *Event

func (*Event) Int8 added in v1.0.0

func (e *Event) Int8(key string, v int8) *Event

func (*Event) Int8p added in v1.0.0

func (e *Event) Int8p(key string, v *int8) *Event

func (*Event) Intp added in v1.0.0

func (e *Event) Intp(key string, v *int) *Event

func (*Event) Msg added in v1.0.0

func (e *Event) Msg(msg string)

NOTICE: once this method is called, the *Event should be disposed.

func (*Event) NamedError added in v1.0.0

func (e *Event) NamedError(key string, val error) *Event

func (*Event) Namespace added in v1.0.0

func (e *Event) Namespace(key string) *Event

func (*Event) Object added in v1.0.0

func (e *Event) Object(key string, val ObjectMarshaler) *Event

func (*Event) Print added in v1.0.0

func (e *Event) Print(args ...any)

NOTICE: once this method is called, the *Event should be disposed.

func (*Event) Printf added in v1.0.0

func (e *Event) Printf(template string, args ...any)

NOTICE: once this method is called, the *Event should be disposed.

func (*Event) Reflect added in v1.0.0

func (e *Event) Reflect(key string, v any) *Event

func (*Event) Stack added in v1.0.0

func (e *Event) Stack(key string) *Event

func (*Event) StackSkip added in v1.0.0

func (e *Event) StackSkip(key string, skip int) *Event

func (*Event) String added in v1.0.0

func (e *Event) String(key string, v string) *Event

func (*Event) Stringer added in v1.0.0

func (e *Event) Stringer(key string, v fmt.Stringer) *Event

func (*Event) Stringp added in v1.0.0

func (e *Event) Stringp(key string, v *string) *Event

func (*Event) Time added in v1.0.0

func (e *Event) Time(key string, v time.Time) *Event

func (*Event) Timep added in v1.0.0

func (e *Event) Timep(key string, v *time.Time) *Event

func (*Event) Uint added in v1.0.0

func (e *Event) Uint(key string, v uint) *Event

func (*Event) Uint16 added in v1.0.0

func (e *Event) Uint16(key string, v uint16) *Event

func (*Event) Uint16p added in v1.0.0

func (e *Event) Uint16p(key string, v *uint16) *Event

func (*Event) Uint32 added in v1.0.0

func (e *Event) Uint32(key string, v uint32) *Event

func (*Event) Uint32p added in v1.0.0

func (e *Event) Uint32p(key string, v *uint32) *Event

func (*Event) Uint64 added in v1.0.0

func (e *Event) Uint64(key string, v uint64) *Event

func (*Event) Uint64p added in v1.0.0

func (e *Event) Uint64p(key string, v *uint64) *Event

func (*Event) Uint8 added in v1.0.0

func (e *Event) Uint8(key string, v uint8) *Event

func (*Event) Uint8p added in v1.0.0

func (e *Event) Uint8p(key string, v *uint8) *Event

func (*Event) Uintp added in v1.0.0

func (e *Event) Uintp(key string, v *uint) *Event

func (*Event) Uintptr added in v1.0.0

func (e *Event) Uintptr(key string, v uintptr) *Event

func (*Event) Uintptrp added in v1.0.0

func (e *Event) Uintptrp(key string, v *uintptr) *Event

func (*Event) With added in v1.0.0

func (e *Event) With(fields ...Field) *Event

func (*Event) WithContext added in v1.0.0

func (e *Event) WithContext(ctx context.Context) *Event

WithContext adds the Go Context to the *Event context. The context is not rendered in the output message, but is available to hooks calls. A typical use case is to extract tracing information from the Go Ctx.

type Field

type Field = zap.Field

func Any

func Any(key string, val any) Field

func Array added in v1.0.0

func Array(key string, val ArrayMarshaler) 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 DefaultCaller

func DefaultCaller(depth int, skipPackages ...string) Field

DefaultCaller caller.

func DefaultCallerFile

func DefaultCallerFile(depth int, skipPackages ...string) Field

DefaultCallerFile caller file.

func Dict

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

func Err(val error) Field

func Errors

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

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

func NamedError(key string, val error) Field

func Namespace

func Namespace(key string) Field

func Object

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 Hook added in v1.0.0

type Hook interface {
	DoHook(ctx context.Context) Field
}

Hook defines an interface to a log hook.

type HookFunc added in v1.0.0

type HookFunc func(context.Context) Field

HookFunc is an adaptor to allow the use of an ordinary function as a Hook.

func Caller

func Caller(depth int, skipPackages ...string) HookFunc

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

func File

func File(depth int, skipPackages ...string) HookFunc

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

func ImmutAny

func ImmutAny(key string, v any) HookFunc

func ImmutBinary

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

func ImmutBool

func ImmutBool(key string, v bool) HookFunc

func ImmutBoolp

func ImmutBoolp(key string, v *bool) HookFunc

func ImmutByteString

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

func ImmutComplex128

func ImmutComplex128(key string, v complex128) HookFunc

func ImmutComplex128p

func ImmutComplex128p(key string, v *complex128) HookFunc

func ImmutComplex64

func ImmutComplex64(key string, v complex64) HookFunc

func ImmutComplex64p

func ImmutComplex64p(key string, v *complex64) HookFunc

func ImmutDict

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

func ImmutDuration

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

func ImmutDurationp

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

func ImmutErr

func ImmutErr(val error) HookFunc

func ImmutErrors

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

func ImmutFloat32

func ImmutFloat32(key string, v float32) HookFunc

func ImmutFloat32p

func ImmutFloat32p(key string, v *float32) HookFunc

func ImmutFloat64

func ImmutFloat64(key string, v float64) HookFunc

func ImmutFloat64p

func ImmutFloat64p(key string, v *float64) HookFunc

func ImmutInline

func ImmutInline(val ObjectMarshaler) HookFunc

func ImmutInt

func ImmutInt(key string, v int) HookFunc

func ImmutInt16

func ImmutInt16(key string, v int16) HookFunc

func ImmutInt16p

func ImmutInt16p(key string, v *int16) HookFunc

func ImmutInt32

func ImmutInt32(key string, v int32) HookFunc

func ImmutInt32p

func ImmutInt32p(key string, v *int32) HookFunc

func ImmutInt64

func ImmutInt64(key string, v int64) HookFunc

func ImmutInt64p

func ImmutInt64p(key string, v *int64) HookFunc

func ImmutInt8

func ImmutInt8(key string, v int8) HookFunc

func ImmutInt8p

func ImmutInt8p(key string, v *int8) HookFunc

func ImmutIntp

func ImmutIntp(key string, v *int) HookFunc

func ImmutNamedError

func ImmutNamedError(key string, val error) HookFunc

func ImmutNamespace

func ImmutNamespace(key string) HookFunc

func ImmutObject

func ImmutObject(key string, val ObjectMarshaler) HookFunc

func ImmutReflect

func ImmutReflect(key string, v any) HookFunc

func ImmutStack

func ImmutStack(key string) HookFunc

func ImmutStackSkip

func ImmutStackSkip(key string, skip int) HookFunc

func ImmutString

func ImmutString(key string, v string) HookFunc

func ImmutStringer

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

func ImmutStringp

func ImmutStringp(key string, v *string) HookFunc

func ImmutTime

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

func ImmutTimep

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

func ImmutUint

func ImmutUint(key string, v uint) HookFunc

func ImmutUint16

func ImmutUint16(key string, v uint16) HookFunc

func ImmutUint16p

func ImmutUint16p(key string, v *uint16) HookFunc

func ImmutUint32

func ImmutUint32(key string, v uint32) HookFunc

func ImmutUint32p

func ImmutUint32p(key string, v *uint32) HookFunc

func ImmutUint64

func ImmutUint64(key string, v uint64) HookFunc

func ImmutUint64p

func ImmutUint64p(key string, v *uint64) HookFunc

func ImmutUint8

func ImmutUint8(key string, v uint8) HookFunc

func ImmutUint8p

func ImmutUint8p(key string, v *uint8) HookFunc

func ImmutUintp

func ImmutUintp(key string, v *uint) HookFunc

func ImmutUintptr

func ImmutUintptr(key string, v uintptr) HookFunc

func ImmutUintptrp

func ImmutUintptrp(key string, v *uintptr) HookFunc

func (HookFunc) DoHook added in v1.0.0

func (hf HookFunc) DoHook(ctx context.Context) Field

DoHook implements the Hook interface.

type ImmutableAny added in v1.0.0

type ImmutableAny ImmutableNamedField[any]

func (*ImmutableAny) DoHook added in v1.0.0

func (m *ImmutableAny) DoHook(ctx context.Context) Field

type ImmutableBinary added in v1.0.0

type ImmutableBinary ImmutableNamedField[[]byte]

func (ImmutableBinary) DoHook added in v1.0.0

func (m ImmutableBinary) DoHook(ctx context.Context) Field

type ImmutableBool added in v1.0.0

type ImmutableBool ImmutableNamedField[bool]

func (*ImmutableBool) DoHook added in v1.0.0

func (m *ImmutableBool) DoHook(ctx context.Context) Field

type ImmutableBoolp added in v1.0.0

type ImmutableBoolp ImmutableNamedField[*bool]

func (*ImmutableBoolp) DoHook added in v1.0.0

func (m *ImmutableBoolp) DoHook(ctx context.Context) Field

type ImmutableByteString added in v1.0.0

type ImmutableByteString ImmutableNamedField[[]byte]

func (*ImmutableByteString) DoHook added in v1.0.0

func (m *ImmutableByteString) DoHook(ctx context.Context) Field

type ImmutableComplex128 added in v1.0.0

type ImmutableComplex128 ImmutableNamedField[complex128]

func (*ImmutableComplex128) DoHook added in v1.0.0

func (m *ImmutableComplex128) DoHook(ctx context.Context) Field

type ImmutableComplex128p added in v1.0.0

type ImmutableComplex128p ImmutableNamedField[*complex128]

func (*ImmutableComplex128p) DoHook added in v1.0.0

func (m *ImmutableComplex128p) DoHook(ctx context.Context) Field

type ImmutableComplex64 added in v1.0.0

type ImmutableComplex64 ImmutableNamedField[complex64]

func (*ImmutableComplex64) DoHook added in v1.0.0

func (m *ImmutableComplex64) DoHook(ctx context.Context) Field

type ImmutableComplex64p added in v1.0.0

type ImmutableComplex64p ImmutableNamedField[*complex64]

func (*ImmutableComplex64p) DoHook added in v1.0.0

func (m *ImmutableComplex64p) DoHook(ctx context.Context) Field

type ImmutableDict added in v1.0.0

type ImmutableDict ImmutableNamedField[[]Field]

func (*ImmutableDict) DoHook added in v1.0.0

func (m *ImmutableDict) DoHook(ctx context.Context) Field

type ImmutableDuration added in v1.0.0

type ImmutableDuration ImmutableNamedField[time.Duration]

func (*ImmutableDuration) DoHook added in v1.0.0

func (m *ImmutableDuration) DoHook(ctx context.Context) Field

type ImmutableDurationp added in v1.0.0

type ImmutableDurationp ImmutableNamedField[*time.Duration]

func (*ImmutableDurationp) DoHook added in v1.0.0

func (m *ImmutableDurationp) DoHook(ctx context.Context) Field

type ImmutableErr added in v1.0.0

type ImmutableErr ImmutableField[error]

func (ImmutableErr) DoHook added in v1.0.0

func (m ImmutableErr) DoHook(ctx context.Context) Field

type ImmutableErrors added in v1.0.0

type ImmutableErrors ImmutableNamedField[[]error]

func (ImmutableErrors) DoHook added in v1.0.0

func (m ImmutableErrors) DoHook(ctx context.Context) Field

type ImmutableField added in v1.0.0

type ImmutableField[T any] struct {
	Value T
}

type ImmutableFloat32 added in v1.0.0

type ImmutableFloat32 ImmutableNamedField[float32]

func (*ImmutableFloat32) DoHook added in v1.0.0

func (m *ImmutableFloat32) DoHook(ctx context.Context) Field

type ImmutableFloat32p added in v1.0.0

type ImmutableFloat32p ImmutableNamedField[*float32]

func (*ImmutableFloat32p) DoHook added in v1.0.0

func (m *ImmutableFloat32p) DoHook(ctx context.Context) Field

type ImmutableFloat64 added in v1.0.0

type ImmutableFloat64 ImmutableNamedField[float64]

func (*ImmutableFloat64) DoHook added in v1.0.0

func (m *ImmutableFloat64) DoHook(ctx context.Context) Field

type ImmutableFloat64p added in v1.0.0

type ImmutableFloat64p ImmutableNamedField[*float64]

func (*ImmutableFloat64p) DoHook added in v1.0.0

func (m *ImmutableFloat64p) DoHook(ctx context.Context) Field

type ImmutableInline added in v1.0.0

type ImmutableInline ImmutableField[ObjectMarshaler]

func (*ImmutableInline) DoHook added in v1.0.0

func (m *ImmutableInline) DoHook(ctx context.Context) Field

type ImmutableInt added in v1.0.0

type ImmutableInt ImmutableNamedField[int]

func (*ImmutableInt) DoHook added in v1.0.0

func (m *ImmutableInt) DoHook(ctx context.Context) Field

type ImmutableInt16 added in v1.0.0

type ImmutableInt16 ImmutableNamedField[int16]

func (*ImmutableInt16) DoHook added in v1.0.0

func (m *ImmutableInt16) DoHook(ctx context.Context) Field

type ImmutableInt16p added in v1.0.0

type ImmutableInt16p ImmutableNamedField[*int16]

func (*ImmutableInt16p) DoHook added in v1.0.0

func (m *ImmutableInt16p) DoHook(ctx context.Context) Field

type ImmutableInt32 added in v1.0.0

type ImmutableInt32 ImmutableNamedField[int32]

func (*ImmutableInt32) DoHook added in v1.0.0

func (m *ImmutableInt32) DoHook(ctx context.Context) Field

type ImmutableInt32p added in v1.0.0

type ImmutableInt32p ImmutableNamedField[*int32]

func (*ImmutableInt32p) DoHook added in v1.0.0

func (m *ImmutableInt32p) DoHook(ctx context.Context) Field

type ImmutableInt64 added in v1.0.0

type ImmutableInt64 ImmutableNamedField[int64]

func (*ImmutableInt64) DoHook added in v1.0.0

func (m *ImmutableInt64) DoHook(ctx context.Context) Field

type ImmutableInt64p added in v1.0.0

type ImmutableInt64p ImmutableNamedField[*int64]

func (*ImmutableInt64p) DoHook added in v1.0.0

func (m *ImmutableInt64p) DoHook(ctx context.Context) Field

type ImmutableInt8 added in v1.0.0

type ImmutableInt8 ImmutableNamedField[int8]

func (*ImmutableInt8) DoHook added in v1.0.0

func (m *ImmutableInt8) DoHook(ctx context.Context) Field

type ImmutableInt8p added in v1.0.0

type ImmutableInt8p ImmutableNamedField[*int8]

func (*ImmutableInt8p) DoHook added in v1.0.0

func (m *ImmutableInt8p) DoHook(ctx context.Context) Field

type ImmutableIntp added in v1.0.0

type ImmutableIntp ImmutableNamedField[*int]

func (*ImmutableIntp) DoHook added in v1.0.0

func (m *ImmutableIntp) DoHook(ctx context.Context) Field

type ImmutableNamedError added in v1.0.0

type ImmutableNamedError ImmutableNamedField[error]

func (ImmutableNamedError) DoHook added in v1.0.0

func (m ImmutableNamedError) DoHook(ctx context.Context) Field

type ImmutableNamedField added in v1.0.0

type ImmutableNamedField[T any] struct {
	Key   string
	Value T
}

type ImmutableNamespace added in v1.0.0

type ImmutableNamespace ImmutableField[string]

func (*ImmutableNamespace) DoHook added in v1.0.0

func (m *ImmutableNamespace) DoHook(ctx context.Context) Field

type ImmutableObject added in v1.0.0

type ImmutableObject ImmutableNamedField[ObjectMarshaler]

func (*ImmutableObject) DoHook added in v1.0.0

func (m *ImmutableObject) DoHook(ctx context.Context) Field

type ImmutableReflect added in v1.0.0

type ImmutableReflect ImmutableNamedField[any]

func (*ImmutableReflect) DoHook added in v1.0.0

func (m *ImmutableReflect) DoHook(ctx context.Context) Field

type ImmutableStack added in v1.0.0

type ImmutableStack struct {
	Key string
}

func (*ImmutableStack) DoHook added in v1.0.0

func (m *ImmutableStack) DoHook(ctx context.Context) Field

type ImmutableStackSkip added in v1.0.0

type ImmutableStackSkip struct {
	Key  string
	Skip int
}

func (*ImmutableStackSkip) DoHook added in v1.0.0

func (m *ImmutableStackSkip) DoHook(ctx context.Context) Field

type ImmutableString added in v1.0.0

type ImmutableString ImmutableNamedField[string]

func (*ImmutableString) DoHook added in v1.0.0

func (m *ImmutableString) DoHook(ctx context.Context) Field

type ImmutableStringer added in v1.0.0

type ImmutableStringer ImmutableNamedField[fmt.Stringer]

func (*ImmutableStringer) DoHook added in v1.0.0

func (m *ImmutableStringer) DoHook(ctx context.Context) Field

type ImmutableStringp added in v1.0.0

type ImmutableStringp ImmutableNamedField[*string]

func (*ImmutableStringp) DoHook added in v1.0.0

func (m *ImmutableStringp) DoHook(ctx context.Context) Field

type ImmutableTime added in v1.0.0

type ImmutableTime ImmutableNamedField[time.Time]

func (*ImmutableTime) DoHook added in v1.0.0

func (m *ImmutableTime) DoHook(ctx context.Context) Field

type ImmutableTimep added in v1.0.0

type ImmutableTimep ImmutableNamedField[*time.Time]

func (*ImmutableTimep) DoHook added in v1.0.0

func (m *ImmutableTimep) DoHook(ctx context.Context) Field

type ImmutableUint added in v1.0.0

type ImmutableUint ImmutableNamedField[uint]

func (*ImmutableUint) DoHook added in v1.0.0

func (m *ImmutableUint) DoHook(ctx context.Context) Field

type ImmutableUint16 added in v1.0.0

type ImmutableUint16 ImmutableNamedField[uint16]

func (*ImmutableUint16) DoHook added in v1.0.0

func (m *ImmutableUint16) DoHook(ctx context.Context) Field

type ImmutableUint16p added in v1.0.0

type ImmutableUint16p ImmutableNamedField[*uint16]

func (*ImmutableUint16p) DoHook added in v1.0.0

func (m *ImmutableUint16p) DoHook(ctx context.Context) Field

type ImmutableUint32 added in v1.0.0

type ImmutableUint32 ImmutableNamedField[uint32]

func (*ImmutableUint32) DoHook added in v1.0.0

func (m *ImmutableUint32) DoHook(ctx context.Context) Field

type ImmutableUint32p added in v1.0.0

type ImmutableUint32p ImmutableNamedField[*uint32]

func (*ImmutableUint32p) DoHook added in v1.0.0

func (m *ImmutableUint32p) DoHook(ctx context.Context) Field

type ImmutableUint64 added in v1.0.0

type ImmutableUint64 ImmutableNamedField[uint64]

func (*ImmutableUint64) DoHook added in v1.0.0

func (m *ImmutableUint64) DoHook(ctx context.Context) Field

type ImmutableUint64p added in v1.0.0

type ImmutableUint64p ImmutableNamedField[*uint64]

func (*ImmutableUint64p) DoHook added in v1.0.0

func (m *ImmutableUint64p) DoHook(ctx context.Context) Field

type ImmutableUint8 added in v1.0.0

type ImmutableUint8 ImmutableNamedField[uint8]

func (*ImmutableUint8) DoHook added in v1.0.0

func (m *ImmutableUint8) DoHook(ctx context.Context) Field

type ImmutableUint8p added in v1.0.0

type ImmutableUint8p ImmutableNamedField[*uint8]

func (*ImmutableUint8p) DoHook added in v1.0.0

func (m *ImmutableUint8p) DoHook(ctx context.Context) Field

type ImmutableUintp added in v1.0.0

type ImmutableUintp ImmutableNamedField[*uint]

func (*ImmutableUintp) DoHook added in v1.0.0

func (m *ImmutableUintp) DoHook(ctx context.Context) Field

type ImmutableUintptr added in v1.0.0

type ImmutableUintptr ImmutableNamedField[uintptr]

func (*ImmutableUintptr) DoHook added in v1.0.0

func (m *ImmutableUintptr) DoHook(ctx context.Context) Field

type ImmutableUintptrp added in v1.0.0

type ImmutableUintptrp ImmutableNamedField[*uintptr]

func (*ImmutableUintptrp) DoHook added in v1.0.0

func (m *ImmutableUintptrp) DoHook(ctx context.Context) 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

func AddCallerSkip

func AddCallerSkip(callerSkip int) *Log

AddCallerSkip add the number of callers skipped by caller annotation.

func AddCallerSkipPackage

func AddCallerSkipPackage(vs ...string) *Log

AddCallerSkipPackage add the caller skip package.

func ExtendDefaultHook added in v1.0.1

func ExtendDefaultHook(hs ...Hook) *Log

ExtendDefaultHook set default hook, which hold always until you call Event.Msg/Event.Print/Event.Printf.

func ExtendDefaultHookFunc added in v1.0.1

func ExtendDefaultHookFunc(hs ...HookFunc) *Log

ExtendDefaultHookFunc set default hook, which hold always until you call Event.Msg/Event.Print/Event.Printf.

func ExtendHook added in v1.0.0

func ExtendHook(hs ...Hook) *Log

ExtendHook creates a child log with extend Hook.

func ExtendHookFunc added in v1.0.0

func ExtendHookFunc(hs ...HookFunc) *Log

ExtendHookFunc creates a child log with extend Hook.

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 默认配置:

Level: 日志等级, 默认warn Format: 编码格式, 默认json EncodeLevel: 编码器类型, 默认LowercaseLevelEncoder Adapter: 默认输出适合器, 默认console` Stack: 是否使能栈调试输出, 默认false Path: 日志保存路径, 默认当前路径 Writer: 当adapter有附带custom时, 如果为writer为空, 将使用os.Stdout EncoderConfig: 如果配置该项,则 EncodeLevel 将被覆盖

文件日志切割配置(启用file时生效) Filename 空字符使用默认, 默认<processname>-lumberjack.log MaxSize 每个日志文件最大尺寸(MB), 默认100MB MaxAge 日志文件保存天数, 默认0 不删除 MaxBackups 日志文件保存备份数, 默认0 都保存 LocalTime 是否格式化时间戳, 默认UTC时间 Compress 是否使用gzip压缩文件, 采用默认不压缩

Caller相关 callerLevel caller日志级别, 默认warn callerSkip caller设置跳过深度, 默认0 callerSkipPackages caller设置跳过的包名, 默认空

func NewLoggerWith

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

NewLoggerWith new logger with zap logger and atomic level

func SetCallerLevel

func SetCallerLevel(lv Level) *Log

SetCallerLevel set the caller level.

func SetLevel

func SetLevel(lv Level) *Log

SetLevel alters the logging level.

func SetNewCallerCore added in v1.0.1

func SetNewCallerCore(c *CallerCore) *Log

SetNewCallerCore overwrite with new caller core

func UnderlyingLogger

func UnderlyingLogger() *Log

UnderlyingLogger underlying global logger.

func UseExternalCallerLevel

func UseExternalCallerLevel(lvl AtomicLevel) *Log

UseExternalCallerLevel use external caller level, which controller by user.

func With

func With(fields ...Field) *Log

With creates a child log and adds structured context to it. Fields added to the child don't affect the parent, and vice versa.

NOTICE: if you do not need a child log, use Event.With instead.

func WithNewHook added in v1.0.0

func WithNewHook(hs ...Hook) *Log

WithNewHook creates a child log with new hook without default hook.

func WithNewHookFunc added in v1.0.0

func WithNewHookFunc(hs ...HookFunc) *Log

WithNewHookFunc creates a child log with new hook func without default hook.

func (*Log) AddCallerSkip

func (l *Log) AddCallerSkip(callerSkip int) *Log

AddCallerSkip add the number of callers skipped by caller annotation.

func (*Log) AddCallerSkipPackage

func (l *Log) AddCallerSkipPackage(vs ...string) *Log

AddCallerSkipPackage add the caller skip package.

func (*Log) DPanic

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

func (*Log) DPanicf

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

func (*Log) Debug

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

func (*Log) Debugf

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

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)

func (*Log) Errorf

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

func (*Log) ExtendDefaultHook added in v1.0.0

func (l *Log) ExtendDefaultHook(hs ...Hook) *Log

ExtendDefaultHook set default hook, which hold always until you call Event.Msg/Event.Print/Event.Printf.

func (*Log) ExtendDefaultHookFunc added in v1.0.0

func (l *Log) ExtendDefaultHookFunc(hs ...HookFunc) *Log

ExtendDefaultHookFunc set default hook, which hold always until you call Event.Msg/Event.Print/Event.Printf.

func (*Log) ExtendHook added in v1.0.0

func (l *Log) ExtendHook(hs ...Hook) *Log

ExtendHook creates a child log with extend Hook.

func (*Log) ExtendHookFunc added in v1.0.0

func (l *Log) ExtendHookFunc(hs ...HookFunc) *Log

ExtendHookFunc creates a child log with extend Hook.

func (*Log) Fatal

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

func (*Log) Fatalf

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

func (*Log) GetLevel

func (l *Log) GetLevel() Level

GetLevel returns the minimum enabled log level.

func (*Log) Info

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

func (*Log) Infof

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

func (*Log) Logger

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

Logger return internal zap.Logger

func (*Log) Named

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

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

func (*Log) OnDPanic added in v1.0.0

func (l *Log) OnDPanic() *Event

OnDPanic starts a new message with DPanicLevel level.

You must call Msg on the returned event in order to send the event.

func (*Log) OnDPanicContext added in v1.0.0

func (l *Log) OnDPanicContext(ctx context.Context) *Event

OnDPanicContext starts a new message with DPanicLevel level, and adds the Go Context to the *Event context.

You must call Msg on the returned event in order to send the event.

func (*Log) OnDebug added in v1.0.0

func (l *Log) OnDebug() *Event

OnDebug starts a new message with DebugLevel level.

You must call Msg on the returned event in order to send the event.

func (*Log) OnDebugContext added in v1.0.0

func (l *Log) OnDebugContext(ctx context.Context) *Event

Debug starts a new message with DebugLevel level, and adds the Go Context to the *Event context.

You must call Msg on the returned event in order to send the event.

func (*Log) OnError added in v1.0.0

func (l *Log) OnError() *Event

OnError starts a new message with ErrorLevel level.

You must call Msg on the returned event in order to send the event.

func (*Log) OnErrorContext added in v1.0.0

func (l *Log) OnErrorContext(ctx context.Context) *Event

OnErrorContext starts a new message with ErrorLevel level, and adds the Go Context to the *Event context.

You must call Msg on the returned event in order to send the event.

func (*Log) OnFatal added in v1.0.0

func (l *Log) OnFatal() *Event

OnFatal starts a new message with FatalLevel level.

You must call Msg on the returned event in order to send the event.

func (*Log) OnFatalContext added in v1.0.0

func (l *Log) OnFatalContext(ctx context.Context) *Event

OnFatalContext starts a new message with FatalLevel level, and adds the Go Context to the *Event context.

You must call Msg on the returned event in order to send the event.

func (*Log) OnInfo added in v1.0.0

func (l *Log) OnInfo() *Event

OnInfo starts a new message with InfoLevel level.

You must call Msg on the returned event in order to send the event.

func (*Log) OnInfoContext added in v1.0.0

func (l *Log) OnInfoContext(ctx context.Context) *Event

OnInfoContext starts a new message with InfoLevel level, and adds the Go Context to the *Event context.

You must call Msg on the returned event in order to send the event.

func (*Log) OnLevel added in v1.0.0

func (l *Log) OnLevel(level Level) *Event

OnLevel starts a new message with customize level.

You must call Msg on the returned event in order to send the event.

func (*Log) OnLevelContext added in v1.0.0

func (l *Log) OnLevelContext(ctx context.Context, level Level) *Event

OnLevelContext starts a new message with customize level, and adds the Go Context to the *Event context.

You must call Msg on the returned event in order to send the event.

func (*Log) OnPanic added in v1.0.0

func (l *Log) OnPanic() *Event

OnPanic starts a new message with PanicLevel level.

You must call Msg on the returned event in order to send the event.

func (*Log) OnPanicContext added in v1.0.0

func (l *Log) OnPanicContext(ctx context.Context) *Event

OnPanicContext starts a new message with PanicLevel level, and adds the Go Context to the *Event context.

You must call Msg on the returned event in order to send the event.

func (*Log) OnWarn added in v1.0.0

func (l *Log) OnWarn() *Event

OnWarn starts a new message with WarnLevel level.

You must call Msg on the returned event in order to send the event.

func (*Log) OnWarnContext added in v1.0.0

func (l *Log) OnWarnContext(ctx context.Context) *Event

OnWarnContext starts a new message with WarnLevel level, and adds the Go Context to the *Event context.

You must call Msg on the returned event in order to send the event.

func (*Log) Panic

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

func (*Log) Panicf

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

func (*Log) SetCaller

func (l *Log) SetCaller(f func(depth int, skipPackages ...string) Field) *Log

SetCaller set the caller function.

func (*Log) SetCallerLevel

func (l *Log) SetCallerLevel(lv Level) *Log

SetCallerLevel set the caller level.

func (*Log) SetLevel

func (l *Log) SetLevel(lv 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) SetNewCallerCore added in v1.0.0

func (l *Log) SetNewCallerCore(c *CallerCore) *Log

SetNewCallerCore overwrite with new caller core

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

func (l *Log) UnderlyingCallerLevel() AtomicLevel

UnderlyingCallerLevel return underlying caller level.

func (*Log) UseExternalCallerLevel

func (l *Log) UseExternalCallerLevel(lvl AtomicLevel) *Log

UseExternalCallerLevel use external caller level, which controller by user.

func (*Log) V

func (l *Log) V(lvl Level) 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)

func (*Log) Warnf

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

func (*Log) With

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

With creates a child log and adds structured context to it. Fields added to the child don't affect the parent, and vice versa.

NOTICE: if you do not need a child log, use Event.With instead.

func (*Log) WithNewHook added in v1.0.0

func (l *Log) WithNewHook(hs ...Hook) *Log

WithNewHook creates a child log with new hook without default hook.

func (*Log) WithNewHookFunc added in v1.0.0

func (l *Log) WithNewHookFunc(hs ...HookFunc) *Log

WithNewHookFunc creates a child log with new hook func without default hook.

type LumberjackFile

type LumberjackFile struct {
	// Path 日志保存路径, 默认 empty, 即当前路径
	Path string `yaml:"path" json:"path"`
	// 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"`
}

type MutableAny added in v1.0.0

type MutableAny MutableNamedField[any]

func (*MutableAny) DoHook added in v1.0.0

func (m *MutableAny) DoHook(ctx context.Context) Field

type MutableBinary added in v1.0.0

type MutableBinary MutableNamedField[[]byte]

func (*MutableBinary) DoHook added in v1.0.0

func (m *MutableBinary) DoHook(ctx context.Context) Field

type MutableBool added in v1.0.0

type MutableBool MutableNamedField[bool]

func (*MutableBool) DoHook added in v1.0.0

func (m *MutableBool) DoHook(ctx context.Context) Field

type MutableBoolp added in v1.0.0

type MutableBoolp MutableNamedField[*bool]

func (*MutableBoolp) DoHook added in v1.0.0

func (m *MutableBoolp) DoHook(ctx context.Context) Field

type MutableByteString added in v1.0.0

type MutableByteString MutableNamedField[[]byte]

func (*MutableByteString) DoHook added in v1.0.0

func (m *MutableByteString) DoHook(ctx context.Context) Field

type MutableComplex128 added in v1.0.0

type MutableComplex128 MutableNamedField[complex128]

func (*MutableComplex128) DoHook added in v1.0.0

func (m *MutableComplex128) DoHook(ctx context.Context) Field

type MutableComplex128p added in v1.0.0

type MutableComplex128p MutableNamedField[*complex128]

func (*MutableComplex128p) DoHook added in v1.0.0

func (m *MutableComplex128p) DoHook(ctx context.Context) Field

type MutableComplex64 added in v1.0.0

type MutableComplex64 MutableNamedField[complex64]

func (*MutableComplex64) DoHook added in v1.0.0

func (m *MutableComplex64) DoHook(ctx context.Context) Field

type MutableComplex64p added in v1.0.0

type MutableComplex64p MutableNamedField[*complex64]

func (*MutableComplex64p) DoHook added in v1.0.0

func (m *MutableComplex64p) DoHook(ctx context.Context) Field

type MutableDict added in v1.0.0

type MutableDict MutableNamedField[[]Field]

func (*MutableDict) DoHook added in v1.0.0

func (m *MutableDict) DoHook(ctx context.Context) Field

type MutableDuration added in v1.0.0

type MutableDuration MutableNamedField[time.Duration]

func (*MutableDuration) DoHook added in v1.0.0

func (m *MutableDuration) DoHook(ctx context.Context) Field

type MutableDurationp added in v1.0.0

type MutableDurationp MutableNamedField[*time.Duration]

func (*MutableDurationp) DoHook added in v1.0.0

func (m *MutableDurationp) DoHook(ctx context.Context) Field

type MutableErr added in v1.0.0

type MutableErr MutableFixedNamedField[error]

func (*MutableErr) DoHook added in v1.0.0

func (m *MutableErr) DoHook(ctx context.Context) Field

type MutableErrors added in v1.0.0

type MutableErrors MutableNamedField[[]error]

func (*MutableErrors) DoHook added in v1.0.0

func (m *MutableErrors) DoHook(ctx context.Context) Field

type MutableFixedNamedField added in v1.0.0

type MutableFixedNamedField[T any] struct {
	Fc func(context.Context) T
}

type MutableFloat32 added in v1.0.0

type MutableFloat32 MutableNamedField[float32]

func (*MutableFloat32) DoHook added in v1.0.0

func (m *MutableFloat32) DoHook(ctx context.Context) Field

type MutableFloat32p added in v1.0.0

type MutableFloat32p MutableNamedField[*float32]

func (*MutableFloat32p) DoHook added in v1.0.0

func (m *MutableFloat32p) DoHook(ctx context.Context) Field

type MutableFloat64 added in v1.0.0

type MutableFloat64 MutableNamedField[float64]

func (*MutableFloat64) DoHook added in v1.0.0

func (m *MutableFloat64) DoHook(ctx context.Context) Field

type MutableFloat64p added in v1.0.0

type MutableFloat64p MutableNamedField[*float64]

func (*MutableFloat64p) DoHook added in v1.0.0

func (m *MutableFloat64p) DoHook(ctx context.Context) Field

type MutableInline added in v1.0.0

func (*MutableInline) DoHook added in v1.0.0

func (m *MutableInline) DoHook(ctx context.Context) Field

type MutableInt added in v1.0.0

type MutableInt MutableNamedField[int]

func (*MutableInt) DoHook added in v1.0.0

func (m *MutableInt) DoHook(ctx context.Context) Field

type MutableInt16 added in v1.0.0

type MutableInt16 MutableNamedField[int16]

func (*MutableInt16) DoHook added in v1.0.0

func (m *MutableInt16) DoHook(ctx context.Context) Field

type MutableInt16p added in v1.0.0

type MutableInt16p MutableNamedField[*int16]

func (*MutableInt16p) DoHook added in v1.0.0

func (m *MutableInt16p) DoHook(ctx context.Context) Field

type MutableInt32 added in v1.0.0

type MutableInt32 MutableNamedField[int32]

func (*MutableInt32) DoHook added in v1.0.0

func (m *MutableInt32) DoHook(ctx context.Context) Field

type MutableInt32p added in v1.0.0

type MutableInt32p MutableNamedField[*int32]

func (*MutableInt32p) DoHook added in v1.0.0

func (m *MutableInt32p) DoHook(ctx context.Context) Field

type MutableInt64 added in v1.0.0

type MutableInt64 MutableNamedField[int64]

func (*MutableInt64) DoHook added in v1.0.0

func (m *MutableInt64) DoHook(ctx context.Context) Field

type MutableInt64p added in v1.0.0

type MutableInt64p MutableNamedField[*int64]

func (*MutableInt64p) DoHook added in v1.0.0

func (m *MutableInt64p) DoHook(ctx context.Context) Field

type MutableInt8 added in v1.0.0

type MutableInt8 MutableNamedField[int8]

func (*MutableInt8) DoHook added in v1.0.0

func (m *MutableInt8) DoHook(ctx context.Context) Field

type MutableInt8p added in v1.0.0

type MutableInt8p MutableNamedField[*int8]

func (*MutableInt8p) DoHook added in v1.0.0

func (m *MutableInt8p) DoHook(ctx context.Context) Field

type MutableIntp added in v1.0.0

type MutableIntp MutableNamedField[*int]

func (*MutableIntp) DoHook added in v1.0.0

func (m *MutableIntp) DoHook(ctx context.Context) Field

type MutableNamedError added in v1.0.0

type MutableNamedError MutableNamedField[error]

func (*MutableNamedError) DoHook added in v1.0.0

func (m *MutableNamedError) DoHook(ctx context.Context) Field

type MutableNamedField added in v1.0.0

type MutableNamedField[T any] struct {
	Key string
	Fc  func(context.Context) T
}

type MutableNamespace added in v1.0.0

type MutableNamespace MutableFixedNamedField[string]

func (*MutableNamespace) DoHook added in v1.0.0

func (m *MutableNamespace) DoHook(ctx context.Context) Field

type MutableObject added in v1.0.0

type MutableObject MutableNamedField[ObjectMarshaler]

func (*MutableObject) DoHook added in v1.0.0

func (m *MutableObject) DoHook(ctx context.Context) Field

type MutableReflect added in v1.0.0

type MutableReflect MutableNamedField[any]

func (*MutableReflect) DoHook added in v1.0.0

func (m *MutableReflect) DoHook(ctx context.Context) Field

type MutableString added in v1.0.0

type MutableString MutableNamedField[string]

func (*MutableString) DoHook added in v1.0.0

func (m *MutableString) DoHook(ctx context.Context) Field

type MutableStringer added in v1.0.0

type MutableStringer MutableNamedField[fmt.Stringer]

func (*MutableStringer) DoHook added in v1.0.0

func (m *MutableStringer) DoHook(ctx context.Context) Field

type MutableStringp added in v1.0.0

type MutableStringp MutableNamedField[*string]

func (*MutableStringp) DoHook added in v1.0.0

func (m *MutableStringp) DoHook(ctx context.Context) Field

type MutableTime added in v1.0.0

type MutableTime MutableNamedField[time.Time]

func (*MutableTime) DoHook added in v1.0.0

func (m *MutableTime) DoHook(ctx context.Context) Field

type MutableTimep added in v1.0.0

type MutableTimep MutableNamedField[*time.Time]

func (*MutableTimep) DoHook added in v1.0.0

func (m *MutableTimep) DoHook(ctx context.Context) Field

type MutableUint added in v1.0.0

type MutableUint MutableNamedField[uint]

func (*MutableUint) DoHook added in v1.0.0

func (m *MutableUint) DoHook(ctx context.Context) Field

type MutableUint16 added in v1.0.0

type MutableUint16 MutableNamedField[uint16]

func (*MutableUint16) DoHook added in v1.0.0

func (m *MutableUint16) DoHook(ctx context.Context) Field

type MutableUint16p added in v1.0.0

type MutableUint16p MutableNamedField[*uint16]

func (*MutableUint16p) DoHook added in v1.0.0

func (m *MutableUint16p) DoHook(ctx context.Context) Field

type MutableUint32 added in v1.0.0

type MutableUint32 MutableNamedField[uint32]

func (*MutableUint32) DoHook added in v1.0.0

func (m *MutableUint32) DoHook(ctx context.Context) Field

type MutableUint32p added in v1.0.0

type MutableUint32p MutableNamedField[*uint32]

func (*MutableUint32p) DoHook added in v1.0.0

func (m *MutableUint32p) DoHook(ctx context.Context) Field

type MutableUint64 added in v1.0.0

type MutableUint64 MutableNamedField[uint64]

func (*MutableUint64) DoHook added in v1.0.0

func (m *MutableUint64) DoHook(ctx context.Context) Field

type MutableUint64p added in v1.0.0

type MutableUint64p MutableNamedField[*uint64]

func (*MutableUint64p) DoHook added in v1.0.0

func (m *MutableUint64p) DoHook(ctx context.Context) Field

type MutableUint8 added in v1.0.0

type MutableUint8 MutableNamedField[uint8]

func (*MutableUint8) DoHook added in v1.0.0

func (m *MutableUint8) DoHook(ctx context.Context) Field

type MutableUint8p added in v1.0.0

type MutableUint8p MutableNamedField[*uint8]

func (*MutableUint8p) DoHook added in v1.0.0

func (m *MutableUint8p) DoHook(ctx context.Context) Field

type MutableUintp added in v1.0.0

type MutableUintp MutableNamedField[*uint]

func (*MutableUintp) DoHook added in v1.0.0

func (m *MutableUintp) DoHook(ctx context.Context) Field

type MutableUintptr added in v1.0.0

type MutableUintptr MutableNamedField[uintptr]

func (*MutableUintptr) DoHook added in v1.0.0

func (m *MutableUintptr) DoHook(ctx context.Context) Field

type MutableUintptrp added in v1.0.0

type MutableUintptrp MutableNamedField[*uintptr]

func (*MutableUintptrp) DoHook added in v1.0.0

func (m *MutableUintptrp) DoHook(ctx context.Context) Field

type ObjectEncoder added in v1.0.0

type ObjectEncoder = zapcore.ObjectEncoder

type ObjectMarshaler

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(default),multi,custom,file-custom,console-custom,multi-custom writer: 当 adapter=custom 使用,如果为writer为空,将使用os.Stdout

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(default): 小写编码器 LowercaseColorLevelEncoder: 小写编码器带颜色 CapitalLevelEncoder: 大写编码器 CapitalColorLevelEncoder: 大写编码器带颜色

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(default) or console

func WithLevel

func WithLevel(level string) Option

WithLevel with level debug(default),info,warn,error,dpanic,panic,fatal

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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