logging

package
v0.25.3 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Logging

type Logging struct {
	ModuleName           string            `mapstructure:"module-name" yaml:"module-name" json:"moduleName"`                                 // 模块名称
	Enabled              bool              `mapstructure:"enabled" yaml:"enabled" json:"enabled"`                                            // 是否启用日志
	Level                string            `mapstructure:"level" yaml:"level" json:"level"`                                                  // 日志级别 (debug, info, warn, error)
	Format               logger.FormatType `mapstructure:"format" yaml:"format" json:"format"`                                               // 日志格式 (json, text, xml, csv)
	Prefix               string            `mapstructure:"prefix" yaml:"prefix" json:"prefix"`                                               // 日志前缀(如:[WSC])
	ShowCaller           bool              `mapstructure:"show-caller" yaml:"show-caller" json:"showCaller"`                                 // 是否显示调用者信息
	Colorful             bool              `mapstructure:"colorful" yaml:"colorful" json:"colorful"`                                         // 是否使用彩色输出
	TimeFormat           string            `mapstructure:"time-format" yaml:"time-format" json:"timeFormat"`                                 // 时间格式(如:2006-01-02 15:04:05.000)
	Output               logger.OutputType `mapstructure:"output" yaml:"output" json:"output"`                                               // 输出目标 (console, file, rotate, stdout, stderr)
	FilePath             string            `mapstructure:"file-path" yaml:"file-path" json:"filePath"`                                       // 日志文件路径
	MaxSize              int               `mapstructure:"max-size" yaml:"max-size" json:"maxSize"`                                          // 最大文件大小(MB)
	MaxBackups           int               `mapstructure:"max-backups" yaml:"max-backups" json:"maxBackups"`                                 // 最大备份文件数
	MaxAge               int               `mapstructure:"max-age" yaml:"max-age" json:"maxAge"`                                             // 最大保存天数
	Compress             bool              `mapstructure:"compress" yaml:"compress" json:"compress"`                                         // 是否压缩
	FilePermission       uint32            `mapstructure:"file-permission" yaml:"file-permission" json:"filePermission"`                     // 文件权限(十进制值,如:420 表示 0644)
	BufferSize           int               `mapstructure:"buffer-size" yaml:"buffer-size" json:"bufferSize"`                                 // 缓冲区大小(字节)
	SkipPaths            []string          `mapstructure:"skip-paths" yaml:"skip-paths" json:"skipPaths"`                                    // 跳过的路径
	EnableRequest        bool              `mapstructure:"enable-request" yaml:"enable-request" json:"enableRequest"`                        // 是否记录请求
	EnableResponse       bool              `mapstructure:"enable-response" yaml:"enable-response" json:"enableResponse"`                     // 是否记录响应
	MaxBodySize          int               `mapstructure:"max-body-size" yaml:"max-body-size" json:"maxBodySize"`                            // 最大日志体大小(字节)
	SensitiveMask        string            `mapstructure:"sensitive-mask" yaml:"sensitive-mask" json:"sensitiveMask"`                        // 敏感数据掩码
	SensitiveKeys        []string          `mapstructure:"sensitive-keys" yaml:"sensitive-keys" json:"sensitiveKeys"`                        // 敏感字段关键词
	SlowHTTPThreshold    int64             `mapstructure:"slow-http-threshold" yaml:"slow-http-threshold" json:"slowHttpThreshold"`          // HTTP慢请求阈值(毫秒)
	SlowGRPCThreshold    int64             `mapstructure:"slow-grpc-threshold" yaml:"slow-grpc-threshold" json:"slowGrpcThreshold"`          // GRPC慢请求阈值(毫秒)
	SlowStreamThreshold  int64             `mapstructure:"slow-stream-threshold" yaml:"slow-stream-threshold" json:"slowStreamThreshold"`    // 流式请求慢请求阈值(毫秒)
	LoggableContentTypes []string          `mapstructure:"loggable-content-types" yaml:"loggable-content-types" json:"loggableContentTypes"` // 可记录的 Content-Type
}

Logging 日志中间件配置

func Default

func Default() *Logging

Default 创建默认日志配置

func (*Logging) AddSkipPath

func (l *Logging) AddSkipPath(path string) *Logging

AddSkipPath 添加跳过的路径

func (*Logging) Clone

func (l *Logging) Clone() internal.Configurable

Clone 返回配置的副本

func (*Logging) Disable

func (l *Logging) Disable() *Logging

Disable 禁用日志中间件

func (*Logging) Enable

func (l *Logging) Enable() *Logging

Enable 启用日志中间件

func (*Logging) EnableLogging

func (l *Logging) EnableLogging() *Logging

EnableLogging 启用日志

func (*Logging) EnableRequestResponse

func (l *Logging) EnableRequestResponse() *Logging

EnableRequestResponse 同时启用请求和响应记录

func (*Logging) Get

func (l *Logging) Get() any

Get 返回配置接口

func (*Logging) GetFormatterType

func (l *Logging) GetFormatterType() logger.FormatType

GetFormatterType 获取 go-logger 的格式化类型

func (*Logging) GetLogLevel

func (l *Logging) GetLogLevel() string

GetLogLevel 获取 go-logger 的日志级别

func (*Logging) GetOutputType

func (l *Logging) GetOutputType() logger.OutputType

GetOutputType 获取 go-logger 的输出类型

func (*Logging) IsEnabled

func (l *Logging) IsEnabled() bool

IsEnabled 检查是否启用

func (*Logging) Set

func (l *Logging) Set(data any)

Set 设置配置数据

func (*Logging) ToLoggerInstance

func (l *Logging) ToLoggerInstance() *logger.Logger

ToLoggerInstance 将 Logging 配置转换为 go-logger 的 Logger 实例

func (*Logging) Validate

func (l *Logging) Validate() error

Validate 验证配置

func (*Logging) WithBufferSize

func (l *Logging) WithBufferSize(bufferSize int) *Logging

WithBufferSize 设置缓冲区大小

func (*Logging) WithCompress

func (l *Logging) WithCompress(compress bool) *Logging

WithCompress 设置是否压缩

func (*Logging) WithEnableRequest

func (l *Logging) WithEnableRequest(enableRequest bool) *Logging

WithEnableRequest 设置是否记录请求

func (*Logging) WithEnableResponse

func (l *Logging) WithEnableResponse(enableResponse bool) *Logging

WithEnableResponse 设置是否记录响应

func (*Logging) WithEnabled

func (l *Logging) WithEnabled(enabled bool) *Logging

WithEnabled 设置是否启用日志

func (*Logging) WithFilePath

func (l *Logging) WithFilePath(filePath string) *Logging

WithFilePath 设置日志文件路径

func (*Logging) WithFilePermission

func (l *Logging) WithFilePermission(permission uint32) *Logging

WithFilePermission 设置文件权限

func (*Logging) WithFormat

func (l *Logging) WithFormat(format logger.FormatType) *Logging

WithFormat 设置日志格式

func (*Logging) WithLevel

func (l *Logging) WithLevel(level string) *Logging

WithLevel 设置日志级别

func (*Logging) WithMaxAge

func (l *Logging) WithMaxAge(maxAge int) *Logging

WithMaxAge 设置最大保存天数

func (*Logging) WithMaxBackups

func (l *Logging) WithMaxBackups(maxBackups int) *Logging

WithMaxBackups 设置最大备份文件数

func (*Logging) WithMaxSize

func (l *Logging) WithMaxSize(maxSize int) *Logging

WithMaxSize 设置最大文件大小

func (*Logging) WithModuleName

func (l *Logging) WithModuleName(moduleName string) *Logging

WithModuleName 设置模块名称

func (*Logging) WithOutput

func (l *Logging) WithOutput(output logger.OutputType) *Logging

WithOutput 设置输出目标

func (*Logging) WithSkipPaths

func (l *Logging) WithSkipPaths(skipPaths []string) *Logging

WithSkipPaths 设置跳过的路径

func (*Logging) WithTimeFormat

func (l *Logging) WithTimeFormat(timeFormat string) *Logging

WithTimeFormat 设置时间格式

Jump to

Keyboard shortcuts

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