log

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package log 提供全局日志功能,支持 ctx 注入 request_id

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Ctx

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

Ctx 从 ctx 获取 logger(自动注入 request_id)

func Debug

func Debug(msg string, fields ...zap.Field)

Debug 调试日志

func DebugCtx

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

DebugCtx 带 ctx 的调试日志

func Error

func Error(msg string, fields ...zap.Field)

Error 错误日志

func ErrorCtx

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

ErrorCtx 带 ctx 的错误日志

func Fatal

func Fatal(msg string, fields ...zap.Field)

Fatal 致命错误日志

func GetRequestID

func GetRequestID(ctx context.Context) string

GetRequestID 从 ctx 获取 request_id

func Info

func Info(msg string, fields ...zap.Field)

Info 信息日志

func InfoCtx

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

InfoCtx 带 ctx 的信息日志

func Init

func Init(cfg Config) error

Init 初始化日志

func L

func L() *zap.Logger

L 返回默认 logger

func S

func S() *zap.SugaredLogger

S 返回默认 sugared logger

func Sync

func Sync() error

Sync 刷新日志缓冲

func Warn

func Warn(msg string, fields ...zap.Field)

Warn 警告日志

func WarnCtx

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

WarnCtx 带 ctx 的警告日志

func WithContext

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

WithContext 将 logger 放入 ctx

Types

type Config

type Config struct {
	Level    string // debug, info, warn, error
	Encoding string // json, console
	Output   string // stdout, stderr, or file path
}

Config 日志配置

Jump to

Keyboard shortcuts

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