Documentation
¶
Index ¶
Constants ¶
const DefaultLoggerName = "default"
DefaultLoggerName 是默认日志记录器的名称。 DefaultLoggerName is the name of the default logger.
Variables ¶
var LogEncodingConfig = zapcore.EncoderConfig{ TimeKey: "time", LevelKey: "level", NameKey: "logger", CallerKey: "caller", FunctionKey: zapcore.OmitKey, MessageKey: "message", StacktraceKey: "stacktrace", LineEnding: zapcore.DefaultLineEnding, EncodeLevel: zapcore.CapitalLevelEncoder, EncodeTime: zapcore.ISO8601TimeEncoder, EncodeDuration: zapcore.StringDurationEncoder, EncodeCaller: zapcore.ShortCallerEncoder, NewReflectedEncoder: UseJSONReflectedEncoder, }
LogEncodingConfig 定义了日志编码的配置。 LogEncodingConfig defines the configuration for log encoding.
Functions ¶
func DefaultAccessEventFunc ¶ added in v0.1.9
DefaultAccessEventFunc 是默认的访问日志事件函数。 DefaultAccessEventFunc is the default access log event function.
func DefaultRecoveryEventFunc ¶ added in v0.1.9
DefaultRecoveryEventFunc 是默认的恢复日志事件函数。 DefaultRecoveryEventFunc is the default recovery log event function.
func UseJSONReflectedEncoder ¶
func UseJSONReflectedEncoder(w io.Writer) zapcore.ReflectedEncoder
UseJSONReflectedEncoder 函数返回一个自定义的 JSON 编码器。 The UseJSONReflectedEncoder function returns a custom JSON encoder.
Types ¶
type LogEvent ¶
type LogEvent struct { // Message 字段表示日志消息 // The Message field represents the log message Message string `json:"message,omitempty" yaml:"message,omitempty"` // ID 字段表示事件的唯一标识符 // The ID field represents the unique identifier of the event ID string `json:"id,omitempty" yaml:"id,omitempty"` // IP 字段表示发起请求的IP地址 // The IP field represents the IP address of the request initiator IP string `json:"ip,omitempty" yaml:"ip,omitempty"` // EndPoint 字段表示请求的终端点 // The EndPoint field represents the endpoint of the request EndPoint string `json:"endpoint,omitempty" yaml:"endpoint,omitempty"` // Path 字段表示请求的路径 // The Path field represents the path of the request Path string `json:"path,omitempty" yaml:"path,omitempty"` // Method 字段表示请求的HTTP方法 // The Method field represents the HTTP method of the request Method string `json:"method,omitempty" yaml:"method,omitempty"` // Code 字段表示响应的HTTP状态码 // The Code field represents the HTTP status code of the response Code int `json:"statusCode,omitempty" yaml:"statusCode,omitempty"` // Status 字段表示请求的状态 // The Status field represents the status of the request Status string `json:"status,omitempty" yaml:"status,omitempty"` // Latency 字段表示请求的延迟时间 // The Latency field represents the latency of the request Latency string `json:"latency,omitempty" yaml:"latency,omitempty"` // Agent 字段表示发起请求的用户代理 // The Agent field represents the user agent of the request initiator Agent string `json:"agent,omitempty" yaml:"agent,omitempty"` // ReqContentType 字段表示请求的内容类型 // The ReqContentType field represents the content type of the request ReqContentType string `json:"reqContentType,omitempty" yaml:"reqContentType,omitempty"` // ReqQuery 字段表示请求的查询参数 // The ReqQuery field represents the query parameters of the request ReqQuery string `json:"query,omitempty" yaml:"query,omitempty"` // ReqBody 字段表示请求的主体内容 // The ReqBody field represents the body of the request ReqBody string `json:"reqBody,omitempty" yaml:"reqBody,omitempty"` // Error 字段表示请求中的任何错误 // The Error field represents any errors in the request Error error `json:"error,omitempty" yaml:"error,omitempty"` // ErrorStack 字段表示错误的堆栈跟踪 // The ErrorStack field represents the stack trace of the error ErrorStack string `json:"errorStack,omitempty" yaml:"errorStack,omitempty"` }
LogEvent 结构体用于记录日志事件 The LogEvent struct is used to log events
type LogrLogger ¶ added in v0.1.9
type LogrLogger struct {
// contains filtered or unexported fields
}
LogrLogger 结构体包装了 logr.Logger 和标准日志记录器。 The LogrLogger struct wraps logr.Logger and standard logger.
func NewLogrLogger ¶ added in v0.1.9
func NewLogrLogger(w io.Writer) *LogrLogger
NewLogrLogger 函数创建并返回一个新的 LogrLogger 实例。 The NewLogrLogger function creates and returns a new LogrLogger instance.
func (*LogrLogger) GetLogrLogger ¶ added in v0.1.9
func (k *LogrLogger) GetLogrLogger() *logr.Logger
GetLogrLogger 方法返回 logr.Logger 的指针。 The GetLogrLogger method returns a pointer to the logr.Logger.
func (*LogrLogger) GetStandardLogger ¶ added in v0.1.9
func (k *LogrLogger) GetStandardLogger() *log.Logger
GetStandardLogger 方法返回标准日志记录器的指针。 The GetStandardLogger method returns a pointer to the standard logger.
func (*LogrLogger) GetStdLogger
deprecated
added in
v0.1.9
func (k *LogrLogger) GetStdLogger() *log.Logger
Deprecated: Use GetStandardLogger instead (since v0.2.9). This method will be removed in the next release.
type ZapLogger ¶ added in v0.1.9
type ZapLogger struct {
// contains filtered or unexported fields
}
ZapLogger 结构体封装了多种类型的日志记录器。 The ZapLogger struct encapsulates multiple types of loggers.
func NewZapLogger ¶ added in v0.1.9
func NewZapLogger(ws zapcore.WriteSyncer, opts ...zap.Option) *ZapLogger
NewZapLogger 函数创建并返回一个新的 ZapLogger 实例。 The NewZapLogger function creates and returns a new ZapLogger instance.
func (*ZapLogger) GetLogrLogger ¶ added in v0.1.9
GetLogrLogger 方法返回 Logr 接口日志记录器。 The GetLogrLogger method returns the Logr interface logger.
func (*ZapLogger) GetStandardLogger ¶ added in v0.1.9
GetStandardLogger 方法返回标准库日志记录器。 The GetStandardLogger method returns the standard library logger.
func (*ZapLogger) GetStdLogger
deprecated
added in
v0.1.9
func (*ZapLogger) GetZapLogger ¶ added in v0.1.9
GetZapLogger 方法返回原始的 Zap 日志记录器。 The GetZapLogger method returns the original Zap logger.
func (*ZapLogger) GetZapSugaredLogger ¶ added in v0.1.9
func (l *ZapLogger) GetZapSugaredLogger() *zap.SugaredLogger
GetZapSugaredLogger 方法返回 Zap 语法糖日志记录器。 The GetZapSugaredLogger method returns the Zap sugared logger.