Documentation
¶
Overview ¶
Package log 表示经过封装的日志功能
Index ¶
- Constants
- Variables
- func CloneContextForConcurrency(ctx context.Context) context.Context
- func CloneContextForDetach(ctx context.Context) context.Context
- func Debug(v ...any)
- func DebugContext(ctx context.Context, v ...any)
- func DebugContextf(ctx context.Context, f string, v ...any)
- func Debugf(f string, v ...any)
- func Error(v ...any)
- func ErrorContext(ctx context.Context, v ...any)
- func ErrorContextf(ctx context.Context, f string, v ...any)
- func Errorf(f string, v ...any)
- func Fatal(v ...any)
- func FatalContext(ctx context.Context, v ...any)
- func FatalContextf(ctx context.Context, f string, v ...any)
- func Fatalf(f string, v ...any)
- func Info(v ...any)
- func InfoContext(ctx context.Context, v ...any)
- func InfoContextf(ctx context.Context, f string, v ...any)
- func Infof(f string, v ...any)
- func RegisterTraceLogFilter()
- func SetLevel(levelString string)
- func ToErrJSON(e error) fmt.Stringer
- func ToJSON(v any) fmt.Stringer
- func ToJSONString(v any) fmt.Stringer
- func Warn(v ...any)
- func WarnContext(ctx context.Context, v ...any)
- func WarnContextf(ctx context.Context, f string, v ...any)
- func Warnf(f string, v ...any)
- func WithLogger(ctx context.Context, l *Logger) context.Context
- type Logger
- func (l *Logger) Debug()
- func (l *Logger) DebugContext(ctx context.Context)
- func (l *Logger) Err(err error) *Logger
- func (l *Logger) Error()
- func (l *Logger) ErrorContext(ctx context.Context)
- func (l *Logger) Fatal()
- func (l *Logger) FatalContext(ctx context.Context)
- func (l *Logger) Format(f string, a ...any) *Logger
- func (l *Logger) Info()
- func (l *Logger) InfoContext(ctx context.Context)
- func (l *Logger) Text(txt string) *Logger
- func (l *Logger) Warn()
- func (l *Logger) WarnContext(ctx context.Context)
- func (l *Logger) With(key string, value any) *Logger
- func (l *Logger) WithCallerStack() *Logger
- func (l *Logger) WithJSON(key string, v any) *Logger
Constants ¶
View Source
const ( // tracelog 的 filter 名称 FilterName = "tracelog" // TraceIDMetadataKey 定义用于传递 trace ID 的 trpc metadata 字段 TraceIDStackMetadataKey = "trace_id_stack" )
Variables ¶
View Source
var EnsureTraceID = trace.EnsureTraceID
EnsureTraceID 确保 context 中有一个 trace ID
View Source
var TraceID = trace.TraceID
TraceID 从 context 中读取 trace ID
View Source
var WithTraceID = trace.WithTraceID
WithTraceID 更新 trace ID
Functions ¶
func CloneContextForConcurrency ¶
CloneContextForConcurrency 复制一个用于并发操作的新的 ctx, 包含 timeout 和 cancel 同步
func CloneContextForDetach ¶
CloneContextForDetach 复制一个用于分离操作的新的 ctx, 不包含 timeout 和 cancel 同步
func DebugContextf ¶
DebugContextf 格式化输出 debug 级别日志
func ErrorContextf ¶
ErrorContextf 格式化输出 error 级别日志
func FatalContextf ¶
FatalContextf 格式化输出 fatal 级别日志
func InfoContextf ¶
InfoContextf 格式化输出 info 级别日志
func RegisterTraceLogFilter ¶
func RegisterTraceLogFilter()
RegisterTraceLogFilter 注册 tracelog filter。请在 trpc.NewServer 之前调用。
func SetLevel ¶
func SetLevel(levelString string)
SetLevel 设置日志级别, 参数为 debug, info, warn, error, fatal 这些
func ToJSONString ¶
func WarnContextf ¶
WarnContextf 格式化输出 warn 级别日志
Types ¶
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger 结构化 logger
func (*Logger) DebugContext ¶
func (*Logger) ErrorContext ¶
func (*Logger) FatalContext ¶
func (*Logger) InfoContext ¶
func (*Logger) WarnContext ¶
func (*Logger) WithCallerStack ¶
WithCallerStack 往 logger 中存入调用链
Click to show internal directories.
Click to hide internal directories.