logging

package
v2.0.0-beta.14 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetLogFilePath

func GetLogFilePath() string

GetLogFilePath 获取日志文件路径

func IsDisabled

func IsDisabled(name string) bool

IsDisabled 检查指定的 logger 是否被禁用 支持前缀匹配,如禁用 "grpc" 会同时禁用 "grpc", "grpc.server", "grpc.client" 等

func List

func List() map[string]Factory

List 返回所有注册的日志工厂(返回副本,线程安全)

func Register

func Register(name string, factory Factory)

Register 注册日志工厂

func SetDisabledLoggers

func SetDisabledLoggers(names []string)

SetDisabledLoggers 设置要禁用的 logger 名称列表 这些 logger 的日志输出将被 EnableChecker 过滤掉

func SetLogFilePath

func SetLogFilePath(path string)

SetLogFilePath 设置日志文件路径

Types

type Config

type Config struct {
	// Level 日志级别: trace, debug, info, warn, error, fatal, panic
	Level string `yaml:"level"`
	// AsJson 终端是否以 JSON 格式输出
	AsJson bool `yaml:"as_json"`
	// DisableLoggers 要禁用日志输出的 logger 名称列表
	// 支持前缀匹配,如 "grpc" 会禁用 "grpc", "grpc.server" 等
	DisableLoggers []string `yaml:"disable_loggers"`
	// Filters expr 表达式过滤器列表,多个表达式以 && 连接
	Filters []string `yaml:"filters"`
	// File 文件输出配置,为空则不输出到文件
	File *FileConfig `yaml:"file"`
}

Config 日志配置

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig 返回默认配置

func (*Config) GetLogFilePath

func (c *Config) GetLogFilePath() string

GetLogFilePath 获取日志文件路径(用于 loggerdebug 读取)

func (*Config) Merge

func (c *Config) Merge(other *Config) *Config

Merge 合并配置,优先使用 other 的非零值

func (*Config) Validate

func (c *Config) Validate() error

Validate 验证配置有效性

type Factory

type Factory func(log log.Logger)

type FileConfig

type FileConfig struct {
	// Enabled 是否启用文件输出
	Enabled bool `yaml:"enabled"`
	// Path 日志文件路径
	Path string `yaml:"path"`
	// MaxSize 单个日志文件最大大小(MB)
	MaxSize int `yaml:"max_size"`
	// MaxBackups 保留的旧日志文件最大数量
	MaxBackups int `yaml:"max_backups"`
	// MaxAge 保留旧日志文件的最大天数
	MaxAge int `yaml:"max_age"`
	// Compress 是否压缩旧日志文件
	Compress bool `yaml:"compress"`
}

FileConfig 文件输出配置

func DefaultFileConfig

func DefaultFileConfig() *FileConfig

DefaultFileConfig 返回默认文件配置

type LogConfigLoader

type LogConfigLoader struct {
	Log *Config `yaml:"logger"`
}

LogConfigLoader 配置加载器

Directories

Path Synopsis
logext

Jump to

Keyboard shortcuts

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