logger

package
v0.0.0-...-a89d057 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DebugLevel = "debug"
	InfoLevel  = "info"
	WarnLevel  = "warn"
	ErrorLevel = "error"
)

Variables

View Source
var Console *zap.Logger
View Source
var Logger *zap.Logger

Functions

func DPanic

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

func Debug

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

func DebugKV

func DebugKV(ctx context.Context, msg string, kvs ...any)

DebugKV logs a debug message with key-value pairs.

func Debugf

func Debugf(ctx context.Context, format string, args ...any)

Debugf writes a formatted debug message with trace context.

func Error

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

func ErrorKV

func ErrorKV(ctx context.Context, msg string, kvs ...any)

ErrorKV logs an error message with key-value pairs.

func Errorf

func Errorf(ctx context.Context, format string, args ...any)

Errorf writes a formatted error message with trace context.

func Fatal

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

func GetLogger

func GetLogger(key string) *zap.Logger

func GetTraceID

func GetTraceID(ctx context.Context) string

func Info

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

func InfoKV

func InfoKV(ctx context.Context, msg string, kvs ...any)

InfoKV logs an info message with key-value pairs.

func Infof

func Infof(ctx context.Context, format string, args ...any)

Infof writes a formatted info message with trace context.

func LevelOf

func LevelOf(level Level) zapcore.Level

func MaskEmail

func MaskEmail(email string) string

MaskEmail masks email addresses (e.g., a***b@example.com).

func MaskPhone

func MaskPhone(phone string) string

MaskPhone masks phone numbers (e.g., 138****1234).

func MaskString

func MaskString(s string, prefixLen, suffixLen int) string

MaskString masks middle characters of a string, keeping prefix and suffix characters.

func MaskToken

func MaskToken(token string) string

MaskToken masks sensitive tokens (e.g., Bearer tokens, API keys, JWTs), keeping header and tail characters.

func NewCtx

func NewCtx(traceIds ...string) context.Context

func Panic

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

func Sugar

func Sugar(ctx context.Context) *zap.SugaredLogger

Sugar returns a sugared logger with context fields attached.

func Warn

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

func WarnKV

func WarnKV(ctx context.Context, msg string, kvs ...any)

WarnKV logs a warning message with key-value pairs.

func Warnf

func Warnf(ctx context.Context, format string, args ...any)

Warnf writes a formatted warn message with trace context.

func With

func With(fields ...zap.Field) *zap.Logger

With creates a child logger with the given zap fields.

func WithContext

func WithContext(ctx context.Context) *zap.Logger

WithContext returns a zap.Logger with the context's TraceID and UserID attached.

Types

type Level

type Level = string

Jump to

Keyboard shortcuts

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