log

package
v1.3.5 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2024 License: MIT Imports: 17 Imported by: 3

README

Read this in other languages: English, 中文.

log

zap_test.go

TestZap

testRunLogServer(t, "log1", "log2")
SetDefaultGenerator(new(GameDefaultFieldGenerator))
SetLogLevel(zap.DebugLevel)

ctx := ContextWithTraceId()
Debug(ctx, "I am debug log1")
LogLess()
Debug(ctx, "I am debug log2")

Info(ctx, "I am info log1: %v", "hello")
LogLess()
Info(ctx, "I am info log2: %v", "hello")

Warn(ctx, "I am warn log1: %v", "hello sam")
LogLess()
Warn(ctx, "I am warn log2: %v", "hello sam")

Error(ctx, "I am error log1: %v, %v", "admin", "eee")
LogLess()
Error(ctx, "I am error log2: %v, %v", "admin", "eee")

ErrorStack(ctx, "I am panic error log1")
LogLess()
ErrorStack(ctx, "I am panic error log2")

Log(ctx, zap.DebugLevel, "I am debug, log1")

testPanicLog(func() {
	panic(errors.New("I am log1"))
})

testPanicLog(func() {
	Panic(context.Background(), "I am panic log1")
})
time.Sleep(time.Second)
TestLevelChange

SetLogLevel(zap.DebugLevel)

if GetLogLevel() != zap.DebugLevel {
	t.FailNow()
}

if LogLess() != zap.InfoLevel {
	t.FailNow()
}

if LogLess() != zap.WarnLevel {
	t.FailNow()
}

if LogLess() != zap.ErrorLevel {
	t.FailNow()
}

if LogLess() != zap.DPanicLevel {
	t.FailNow()
}

if LogLess() != zap.PanicLevel {
	t.FailNow()
}

if LogLess() != zap.FatalLevel {
	t.FailNow()
}

if LogLess() != zap.FatalLevel {
	t.FailNow()
}

SetLogLevel(zap.FatalLevel)

if LogMore() != zap.PanicLevel {
	t.FailNow()
}

if LogMore() != zap.DPanicLevel {
	t.FailNow()
}

if LogMore() != zap.ErrorLevel {
	t.FailNow()
}

if LogMore() != zap.WarnLevel {
	t.FailNow()
}

if LogMore() != zap.InfoLevel {
	t.FailNow()
}

if LogMore() != zap.DebugLevel {
	t.FailNow()
}

if LogMore() != zap.DebugLevel {
	t.FailNow()
}
TestNewTraceId

t.Log(NewTraceId())

Documentation

Index

Constants

View Source
const (
	LOG_TRACE_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 ContextWithTraceId added in v1.3.5

func ContextWithTraceId() context.Context

func ContextWithTraceIdFromParent added in v1.3.5

func ContextWithTraceIdFromParent(parent context.Context) context.Context

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 GetLogLevel added in v1.3.5

func GetLogLevel() zapcore.Level

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 NewTraceId added in v1.3.5

func NewTraceId() string

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 SetLogLevel added in v1.3.5

func SetLogLevel(l zapcore.Level) zapcore.Level

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