log

package
v1.1.35 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2023 License: MIT Imports: 15 Imported by: 3

README

log zap日志库

zap_test.go

TestZap

ctx := &gin.Context{}
ctx.Set(LOG_TRADE_ID, "aaabbbbbcccc")

Info(ctx, "我是日志2")
Error(ctx, "我是日志4: %v,%v", "管理员", "eee")
TestErrorStack

ErrorStack(context.Background(), "panic error")
TestPanicLog

testPanicLog()

Info(context.Background(), "catch panic")
TestLevelChange

traceId := time.Now().Unix()
ctx := context.WithValue(context.Background(), LOG_TRADE_ID, traceId)
Error(ctx, LogLess())
Error(ctx, LogLess())
Error(ctx, LogLess())
Error(ctx, LogLess())
Error(ctx, LogLess())
Error(ctx, LogLess())
Error(ctx, LogLess())
Error(ctx, LogLess())

fmt.Println(LogLess(), "============")

Info(ctx, LogMore())
Info(ctx, LogMore())
Info(ctx, LogMore())
Info(ctx, LogMore())
Info(ctx, LogMore())
Info(ctx, LogMore())
Info(ctx, LogMore())
Info(ctx, LogMore())

fmt.Println(LogMore(), "============")

Documentation

Index

Constants

View Source
const (
	LOG_TRADE_ID            = "__GTraceId__"
	LOG_JSON_FIELD_TRACE_ID = "traceId"

	LOGGER_ENCODER_JSON    = "json"
	LOGGER_ENCODER_CONSOLE = "console"
)

Variables

This section is empty.

Functions

func CnTimeEncoder

func CnTimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder)

func Debug

func Debug(c context.Context, args ...interface{})

func Error

func Error(c context.Context, args ...interface{})

func ErrorStack added in v1.1.25

func ErrorStack(c context.Context, args ...interface{})

func Fatal

func Fatal(c context.Context, args ...interface{})

func Info

func Info(c context.Context, args ...interface{})

func Log

func Log(c context.Context, level zapcore.Level, args ...interface{})

func LogLess

func LogLess() zapcore.Level

func LogMore

func LogMore() zapcore.Level

func Panic

func Panic(c context.Context, args ...interface{})

func Recover

func Recover(c context.Context, errHandler func(interface{}) string)

func SetDefaultGenerator added in v1.1.29

func SetDefaultGenerator(g DefaultFieldsGenerator)

func SupplementFields added in v1.1.29

func SupplementFields(ctx context.Context) []zap.Field

func Warn

func Warn(c context.Context, args ...interface{})

Types

type DefaultFieldsGenerator added in v1.1.29

type DefaultFieldsGenerator interface {
	GetDefaultFields() []zap.Field
}

DefaultFieldsGenerator 默认值入参

type DefaultGenerator added in v1.1.29

type DefaultGenerator struct {
}

func (*DefaultGenerator) GetDefaultFields added in v1.1.29

func (f *DefaultGenerator) GetDefaultFields() []zap.Field

Jump to

Keyboard shortcuts

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