Documentation
¶
Index ¶
- Constants
- func GrpcStreamServerInterceptor(logger Logger) grpc.StreamServerInterceptor
- func GrpcUnaryClientInterceptor(logger Logger) grpc.UnaryClientInterceptor
- func GrpcUnaryServerInterceptor(logger Logger) grpc.UnaryServerInterceptor
- func SetDefaultLogger(logger Logger)
- type LogLevel
- type Logger
- type Options
- type StructuredLogger
- func (l *StructuredLogger) Debug(msg string, fields map[string]interface{})
- func (l *StructuredLogger) Error(msg string, fields map[string]interface{})
- func (l *StructuredLogger) Fatal(msg string, fields map[string]interface{})
- func (l *StructuredLogger) GetLevel() LogLevel
- func (l *StructuredLogger) Info(msg string, fields map[string]interface{})
- func (l *StructuredLogger) Log(level LogLevel, msg string, fields map[string]interface{})
- func (l *StructuredLogger) SetLevel(level LogLevel)
- func (l *StructuredLogger) Warn(msg string, fields map[string]interface{})
- func (l *StructuredLogger) With(fields map[string]interface{}) Logger
Constants ¶
View Source
const ( FieldTime = "time" FieldLevel = "level" FieldMessage = "message" FieldFile = "file" FieldLine = "line" FieldService = "service" FieldMethod = "method" FieldDuration = "duration_ms" FieldStatus = "status" FieldError = "error" FieldTraceID = "trace_id" FieldSpanID = "span_id" )
公共字段名
Variables ¶
This section is empty.
Functions ¶
func GrpcStreamServerInterceptor ¶
func GrpcStreamServerInterceptor(logger Logger) grpc.StreamServerInterceptor
GrpcStreamServerInterceptor 返回一个用于记录gRPC流式调用的拦截器
func GrpcUnaryClientInterceptor ¶
func GrpcUnaryClientInterceptor(logger Logger) grpc.UnaryClientInterceptor
GrpcUnaryClientInterceptor 返回一个用于记录gRPC客户端一元调用的拦截器
func GrpcUnaryServerInterceptor ¶
func GrpcUnaryServerInterceptor(logger Logger) grpc.UnaryServerInterceptor
GrpcUnaryServerInterceptor 返回一个用于记录gRPC一元调用的拦截器
Types ¶
type Logger ¶
type Logger interface {
// 写入指定级别的日志
Log(level LogLevel, msg string, fields map[string]interface{})
// 调试日志
Debug(msg string, fields map[string]interface{})
// 普通信息
Info(msg string, fields map[string]interface{})
// 警告信息
Warn(msg string, fields map[string]interface{})
// 错误信息
Error(msg string, fields map[string]interface{})
// 严重错误
Fatal(msg string, fields map[string]interface{})
// 创建子日志
With(fields map[string]interface{}) Logger
// 设置日志级别
SetLevel(level LogLevel)
// 获取日志级别
GetLevel() LogLevel
}
Logger 是结构化日志接口
type Options ¶
type Options struct {
// 输出位置
Writer io.Writer
// 最低日志级别
Level LogLevel
// 是否包含调用位置
IncludeLocation bool
// 服务名称
ServiceName string
// 是否使用彩色输出
EnableColor bool
// 是否格式化JSON输出
PrettyPrint bool
}
Options 定义日志选项
type StructuredLogger ¶
type StructuredLogger struct {
// contains filtered or unexported fields
}
StructuredLogger 实现结构化日志
func NewStructuredLogger ¶
func NewStructuredLogger(opts Options) *StructuredLogger
NewStructuredLogger 创建新的结构化日志器
func (*StructuredLogger) Debug ¶
func (l *StructuredLogger) Debug(msg string, fields map[string]interface{})
Debug 记录调试日志
func (*StructuredLogger) Error ¶
func (l *StructuredLogger) Error(msg string, fields map[string]interface{})
Error 记录错误信息
func (*StructuredLogger) Fatal ¶
func (l *StructuredLogger) Fatal(msg string, fields map[string]interface{})
Fatal 记录致命错误并退出
func (*StructuredLogger) Info ¶
func (l *StructuredLogger) Info(msg string, fields map[string]interface{})
Info 记录普通信息
func (*StructuredLogger) Log ¶
func (l *StructuredLogger) Log(level LogLevel, msg string, fields map[string]interface{})
Log 记录指定级别的日志
func (*StructuredLogger) SetLevel ¶
func (l *StructuredLogger) SetLevel(level LogLevel)
SetLevel 设置日志级别
func (*StructuredLogger) Warn ¶
func (l *StructuredLogger) Warn(msg string, fields map[string]interface{})
Warn 记录警告信息
func (*StructuredLogger) With ¶
func (l *StructuredLogger) With(fields map[string]interface{}) Logger
With 创建带有额外字段的子日志器
Click to show internal directories.
Click to hide internal directories.