wlog

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2023 License: MIT Imports: 12 Imported by: 0

README

wlog

GoDoc Go.Dev reference codecov Go Report Card Licence Tag

Features

Usage

Installation

Use go get.

    go get github.com/wyy-go/wlog

Then import the package into your own code.

    import "github.com/wyy-go/wlog"
Example
package main

import (
	"context"
	"github.com/wyy-go/wlog"
	"os"
)

func main() {
	l, lvl := wlog.New(
		wlog.WithLevel("debug"),
		wlog.WithFormat("console"),
		wlog.WithStack(true),
		wlog.WithAdapter("file-custom", os.Stderr),
		wlog.WithPath(""),
		wlog.WithAddCaller(true),

		wlog.WithFilename("log.log"),
		wlog.WithMaxSize(100),
		wlog.WithMaxAge(7),
		wlog.WithMaxBackups(7),
		wlog.WithEnableLocalTime(),
		wlog.WithEnableCompress(),
	)
	wlog.ReplaceGlobals(wlog.NewLoggerWith(l, lvl).Named("project"))
	wlog.SetDefaultValuer(
		wlog.ImmutString("field_fn_key1", "field_fn_value1"),
	)

	wlog.Debug("Debug")
	wlog.Debug("Debug", "-", "111111", "-", 1)
	wlog.Info("Info")
	wlog.Warn("Warn")
	wlog.Info("info")
	wlog.Error("Error")
	wlog.DPanic("DPanic")

	wlog.Debugf("Debugf: %s", "debug")
	wlog.Infof("Infof: %s", "info")
	wlog.Warnf("Warnf: %s", "warn")
	wlog.Infof("Infof: %s", "info")
	wlog.Errorf("Errorf: %s", "error")
	wlog.DPanicf("DPanicf: %s", "dPanic")

	wlog.Debugw("Debugw", "Debugw", "w", "11111111", "2222222222")
	wlog.Infow("Infow", "Infow", "w")
	wlog.Warnw("Warnw", "Warnw", "w")
	wlog.Infow("Infow", "Infow", "w")
	wlog.Errorw("Errorw", "Errorw", "w")
	wlog.DPanicw("DPanicw", "DPanicw", "w")

	shouPanic(func() {
		wlog.Panic("Panic")
	})
	shouPanic(func() {
		wlog.Panicf("Panicf: %s", "panic")
	})
	shouPanic(func() {
		wlog.Panicw("Panicw: %s", "panic", "w")
	})

	wlog.With(wlog.String("aa", "bb")).Debug("debug with")

	wlog.Named("another").Debug("debug named")

	wlog.WithContext(context.Background()).
		WithValuer(func(ctx context.Context) wlog.Field { return wlog.String("field_fn_key2", "field_fn_value2") }).
		Debug("with context")

	wlog.WithContext(context.Background()).
		WithValuer(func(ctx context.Context) wlog.Field { return wlog.String("field_fn_key3", "field_fn_value3") }).
		Debug("with field fn")

	wlog.With(wlog.Namespace("aaaa")).With(wlog.String("xx", "yy")).With(wlog.Namespace("bbbbbb")).With(wlog.String("dd", "gg")).Debug()

	_ = wlog.Sync()

}

func shouPanic(f func()) {
	defer func() {
		e := recover()
		if e == nil {
			wlog.Errorf("should panic but not")
		}
	}()
	f()
}

Output:

2023-02-21 02:04:21.025	debug	project	example/main.go:30	{"msg": "Debug", "field_fn_key1": "field_fn_value1"}
2023-02-21 02:04:21.061	debug	project	example/main.go:31	{"msg": "Debug-111111-1", "field_fn_key1": "field_fn_value1"}
2023-02-21 02:04:21.062	info	project	example/main.go:32	{"msg": "Info", "field_fn_key1": "field_fn_value1"}
2023-02-21 02:04:21.062	warn	project	example/main.go:33	{"msg": "Warn", "field_fn_key1": "field_fn_value1"}
2023-02-21 02:04:21.062	info	project	example/main.go:34	{"msg": "info", "field_fn_key1": "field_fn_value1"}
2023-02-21 02:04:21.062	error	project	example/main.go:35	{"msg": "Error", "field_fn_key1": "field_fn_value1"}
2023-02-21 02:04:21.062	dpanic	project	example/main.go:36	{"msg": "DPanic", "field_fn_key1": "field_fn_value1"}
github.com/wyy-go/wlog.(*Log).DPanic
	C:/Users/wangyangyang/Desktop/qwqqq/wlog/logger.go:182
github.com/wyy-go/wlog.DPanic
	C:/Users/wangyangyang/Desktop/qwqqq/wlog/default.go:106
main.main
	C:/Users/wangyangyang/Desktop/qwqqq/wlog/example/main.go:36
runtime.main
	D:/gvm/go/src/runtime/proc.go:250
2023-02-21 02:04:21.063	debug	project	example/main.go:38	{"msg": "Debugf: debug", "field_fn_key1": "field_fn_value1"}
2023-02-21 02:04:21.063	info	project	example/main.go:39	{"msg": "Infof: info", "field_fn_key1": "field_fn_value1"}
2023-02-21 02:04:21.063	warn	project	example/main.go:40	{"msg": "Warnf: warn", "field_fn_key1": "field_fn_value1"}
2023-02-21 02:04:21.063	info	project	example/main.go:41	{"msg": "Infof: info", "field_fn_key1": "field_fn_value1"}
2023-02-21 02:04:21.063	error	project	example/main.go:42	{"msg": "Errorf: error", "field_fn_key1": "field_fn_value1"}
2023-02-21 02:04:21.064	dpanic	project	example/main.go:43	{"msg": "DPanicf: dPanic", "field_fn_key1": "field_fn_value1"}
github.com/wyy-go/wlog.(*Log).DPanicf
	C:/Users/wangyangyang/Desktop/qwqqq/wlog/logger.go:239
github.com/wyy-go/wlog.DPanicf
	C:/Users/wangyangyang/Desktop/qwqqq/wlog/default.go:128
main.main
	C:/Users/wangyangyang/Desktop/qwqqq/wlog/example/main.go:43
runtime.main
	D:/gvm/go/src/runtime/proc.go:250
2023-02-21 02:04:21.064	debug	project	example/main.go:45	{"msg": "Debugw", "field_fn_key1": "field_fn_value1", "Debugw": "w", "11111111": "2222222222"}
2023-02-21 02:04:21.064	info	project	example/main.go:46	{"msg": "Infow", "field_fn_key1": "field_fn_value1", "Infow": "w"}
2023-02-21 02:04:21.065	warn	project	example/main.go:47	{"msg": "Warnw", "field_fn_key1": "field_fn_value1", "Warnw": "w"}
2023-02-21 02:04:21.065	info	project	example/main.go:48	{"msg": "Infow", "field_fn_key1": "field_fn_value1", "Infow": "w"}
2023-02-21 02:04:21.065	error	project	example/main.go:49	{"msg": "Errorw", "field_fn_key1": "field_fn_value1", "Errorw": "w"}
2023-02-21 02:04:21.065	dpanic	project	example/main.go:50	{"msg": "DPanicw", "field_fn_key1": "field_fn_value1", "DPanicw": "w"}
github.com/wyy-go/wlog.(*Log).DPanicw
	C:/Users/wangyangyang/Desktop/qwqqq/wlog/logger.go:305
github.com/wyy-go/wlog.DPanicw
	C:/Users/wangyangyang/Desktop/qwqqq/wlog/default.go:159
main.main
	C:/Users/wangyangyang/Desktop/qwqqq/wlog/example/main.go:50
runtime.main
	D:/gvm/go/src/runtime/proc.go:250
2023-02-21 02:04:21.065	panic	project	example/main.go:53	{"msg": "Panic", "field_fn_key1": "field_fn_value1"}
github.com/wyy-go/wlog.(*Log).Panic
	C:/Users/wangyangyang/Desktop/qwqqq/wlog/logger.go:190
github.com/wyy-go/wlog.Panic
	C:/Users/wangyangyang/Desktop/qwqqq/wlog/default.go:109
main.main.func1
	C:/Users/wangyangyang/Desktop/qwqqq/wlog/example/main.go:53
main.shouPanic
	C:/Users/wangyangyang/Desktop/qwqqq/wlog/example/main.go:87
main.main
	C:/Users/wangyangyang/Desktop/qwqqq/wlog/example/main.go:52
runtime.main
	D:/gvm/go/src/runtime/proc.go:250
2023-02-21 02:04:21.066	panic	project	example/main.go:56	{"msg": "Panicf: panic", "field_fn_key1": "field_fn_value1"}
github.com/wyy-go/wlog.(*Log).Panicf
	C:/Users/wangyangyang/Desktop/qwqqq/wlog/logger.go:247
github.com/wyy-go/wlog.Panicf
	C:/Users/wangyangyang/Desktop/qwqqq/wlog/default.go:131
main.main.func2
	C:/Users/wangyangyang/Desktop/qwqqq/wlog/example/main.go:56
main.shouPanic
	C:/Users/wangyangyang/Desktop/qwqqq/wlog/example/main.go:87
main.main
	C:/Users/wangyangyang/Desktop/qwqqq/wlog/example/main.go:55
runtime.main
	D:/gvm/go/src/runtime/proc.go:250
2023-02-21 02:04:21.066	panic	project	example/main.go:59	{"msg": "Panicw: %s", "field_fn_key1": "field_fn_value1", "panic": "w"}
github.com/wyy-go/wlog.(*Log).Panicw
	C:/Users/wangyangyang/Desktop/qwqqq/wlog/logger.go:314
github.com/wyy-go/wlog.Panicw
	C:/Users/wangyangyang/Desktop/qwqqq/wlog/default.go:163
main.main.func3
	C:/Users/wangyangyang/Desktop/qwqqq/wlog/example/main.go:59
main.shouPanic
	C:/Users/wangyangyang/Desktop/qwqqq/wlog/example/main.go:87
main.main
	C:/Users/wangyangyang/Desktop/qwqqq/wlog/example/main.go:58
runtime.main
	D:/gvm/go/src/runtime/proc.go:250
2023-02-21 02:04:21.067	debug	project	example/main.go:62	{"aa": "bb", "msg": "debug with", "field_fn_key1": "field_fn_value1"}
2023-02-21 02:04:21.067	debug	project.another	example/main.go:64	{"msg": "debug named", "field_fn_key1": "field_fn_value1"}
2023-02-21 02:04:21.067	debug	project	example/main.go:68	{"msg": "with context", "field_fn_key1": "field_fn_value1", "field_fn_key2": "field_fn_value2"}
2023-02-21 02:04:21.067	debug	project	example/main.go:72	{"msg": "with field fn", "field_fn_key1": "field_fn_value1", "field_fn_key3": "field_fn_value3"}
2023-02-21 02:04:21.067	debug	project	example/main.go:74	{"aaaa": {"xx": "yy", "bbbbbb": {"dd": "gg", "msg": "", "field_fn_key1": "field_fn_value1"}}}

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
)

Variables

View Source
var (
	Skip        = zap.Skip
	Binary      = zap.Binary
	Bool        = zap.Bool
	Boolp       = zap.Boolp
	ByteString  = zap.ByteString
	Complex128  = zap.Complex128
	Complex128p = zap.Complex128p
	Complex64   = zap.Complex64
	Complex64p  = zap.Complex64p
	Float64     = zap.Float64
	Float64p    = zap.Float64p
	Float32     = zap.Float32
	Float32p    = zap.Float32p
	Int         = zap.Int
	Intp        = zap.Intp
	Int64       = zap.Int64
	Int64p      = zap.Int64p
	Int32       = zap.Int32
	Int32p      = zap.Int32p
	Int16       = zap.Int16
	Int16p      = zap.Int16p
	Int8        = zap.Int8
	Int8p       = zap.Int8p
	String      = zap.String
	Stringp     = zap.Stringp
	Uint        = zap.Uint
	Uintp       = zap.Uintp
	Uint64      = zap.Uint64
	Uint64p     = zap.Uint64p
	Uint32      = zap.Uint32
	Uint32p     = zap.Uint32p
	Uint16      = zap.Uint16
	Uint16p     = zap.Uint16p
	Uint8       = zap.Uint8
	Uint8p      = zap.Uint8p
	Uintptr     = zap.Uintptr
	Uintptrp    = zap.Uintptrp
	Reflect     = zap.Reflect
	Namespace   = zap.Namespace
	Stringer    = zap.Stringer
	Time        = zap.Time
	Timep       = zap.Timep
	Stack       = zap.Stack
	StackSkip   = zap.StackSkip
	Duration    = zap.Duration
	Durationp   = zap.Durationp
	Any         = zap.Any
)

Functions

func DPanic

func DPanic(args ...any)

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

func DPanicf

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

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

func DPanicw

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

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

func Debug

func Debug(args ...any)

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

func Debugf

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

Debugf uses fmt.Sprintf to log a templated message.

func Debugw

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

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

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

s.With(keysAndValues).Debug(msg)

func Enabled

func Enabled(lvl zapcore.Level) bool

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

func Error

func Error(args ...any)

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

func Errorf

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

Errorf uses fmt.Sprintf to log a templated message.

func Errorw

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

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

func Fatal

func Fatal(args ...any)

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

func Fatalf

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

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

func Fatalw

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

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

func GetLevel

func GetLevel() zapcore.Level

GetLevel returns the minimum enabled log level.

func Info

func Info(args ...any)

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

func Infof

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

Infof uses fmt.Sprintf to log a templated message.

func Infow

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

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

func New

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

New constructs a new Log

func Panic

func Panic(args ...any)

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

func Panicf

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

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

func Panicw

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

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

func ReplaceGlobals

func ReplaceGlobals(logger *Log)

ReplaceGlobals replaces the global Log,

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

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

func Warnf

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

Warnf uses fmt.Sprintf to log a templated message.

func Warnw

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

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

Types

type Config

type Config struct {
	// Level 日志等级, debug,info,warn,error,dpanic,panic,fatal, 默认warn
	Level string `yaml:"level" json:"level"`
	// Format: 编码格式: json,console 默认json
	Format string `yaml:"format" json:"format"`
	// Adapter 输出适配器, file,console,multi,custom,file-custom,console-custom,multi-custom 默认 console
	Adapter string `yaml:"adapter" json:"adapter"`
	// Stack 是否使能栈调试输出, 默认false
	Stack bool `yaml:"stack" json:"stack"`
	// AddCaller add caller
	AddCaller bool `yaml:"addCaller" json:"addCaller"`
	// CallerSkip call skip if AddCaller enabled
	CallerSkip int `yaml:"callerSkip" json:"callerSkip"`
	// Path 日志保存路径, 默认 empty, 即当前路径
	Path string `yaml:"path" json:"path"`
	// Writer 输出
	// 当 adapter=custom使用,如果为writer为空,将使用os.Stdout
	Writer []io.Writer `yaml:"-" json:"-"`

	// see https://github.com/natefinch/lumberjack
	// lumberjack.Log
	// Filename 空字符使用默认, 默认<processname>-lumberjack.log
	Filename string `yaml:"filename" json:"filename"`
	// MaxSize 每个日志文件最大尺寸(MB), 默认100MB
	MaxSize int `yaml:"maxSize" json:"maxSize"`
	// MaxAge 日志文件保存天数, 默认0 不删除
	MaxAge int `yaml:"maxAge" json:"maxAge"`
	// MaxBackups 日志文件保存备份数, 默认0 都保存
	MaxBackups int `yaml:"maxBackups" json:"maxBackups"`
	// LocalTime 是否格式化时间戳, 默认UTC时间
	LocalTime bool `yaml:"localTime" json:"localTime"`
	// Compress 是否使用gzip压缩文件, 采用默认不压缩
	Compress bool `yaml:"compress" json:"compress"`
}

Config 日志配置

type Field

type Field = zap.Field

type Level

type Level = zapcore.Level

type Log

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

Log wrap zap logger

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.

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

func WithContext(ctx context.Context) *Log

WithContext return log with inject context.

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 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 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 logs a message with some additional context. In development, the logger then panics. (See DPanicLevel for details.) The variadic key-value pairs are treated as they are in With.

func (*Log) Debug

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

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

func (*Log) Debugf

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

Debugf uses fmt.Sprintf to log a templated message.

func (*Log) Debugw

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

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

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

s.With(keysAndValues).Debug(msg)

func (*Log) Enabled

func (l *Log) Enabled(lvl zapcore.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 uses fmt.Sprint to construct and log a message.

func (*Log) Errorf

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

Errorf uses fmt.Sprintf to log a templated message.

func (*Log) Errorw

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

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

func (*Log) Fatal

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

Fatal 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 uses fmt.Sprintf to log a templated message, then calls os.Exit.

func (*Log) Fatalw

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

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

func (*Log) GetLevel

func (l *Log) GetLevel() zapcore.Level

GetLevel returns the minimum enabled log level.

func (*Log) Info

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

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

func (*Log) Infof

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

Infof uses fmt.Sprintf to log a templated message.

func (*Log) Infow

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

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

func (*Log) Logger

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

Logger return internal logger

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 uses fmt.Sprint to construct and log a message, then panics.

func (*Log) Panicf

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

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

func (*Log) Panicw

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

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

func (*Log) SetDefaultValuer

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 uses fmt.Sprint to construct and log a message.

func (*Log) Warnf

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

Warnf uses fmt.Sprintf to log a templated message.

func (*Log) Warnw

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

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

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

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

WithContext return log with 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 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 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 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 Component

func Component(v string) Valuer

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 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 FromNamespace

func FromNamespace(key string) Valuer

func FromReflect

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

func FromStack

func FromStack(key string) Valuer

func FromStackSkip

func FromStackSkip(key string, skip int) 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 ImmutDuration

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

func ImmutDurationp

func ImmutDurationp(key string, v *time.Duration) 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 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 ImmutReflect

func ImmutReflect(key string, v any) 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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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