log

package
v2.0.86 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2025 License: MIT Imports: 16 Imported by: 141

Documentation

Index

Constants

View Source
const (
	AppName = "log"
)
View Source
const RECOVERY_BUF_SIZE = 64 << 1
View Source
const (
	SUB_LOGGER_KEY = "logger"
)

Variables

This section is empty.

Functions

func FromCtx added in v2.0.77

func FromCtx(ctx context.Context, names ...string) *zerolog.Logger

func L

func L() *zerolog.Logger

func Recover added in v2.0.41

func Recover()

func Sub

func Sub(name string) *zerolog.Logger

Types

type Config

type Config struct {
	// 0 为打印日志全路径, 默认打印2层路径
	CallerDeep int `toml:"caller_deep" json:"caller_deep" yaml:"caller_deep"  env:"CALLER_DEEP"`
	// 日志的级别, 默认Debug
	Level string `toml:"level" json:"level" yaml:"level"  env:"LEVEL"`
	// 时间字段名, 默认为timestamp
	TimestampField string `toml:"timestamp_field" json:"timestamp_field" yaml:"timestamp_field"  env:"TIMESTAMP_FIELD"`
	// 日志级别字段名, 默认level
	LevelField string `toml:"level_field" json:"level_field" yaml:"level_field"  env:"LEVEL_FIELD"`
	// 日志消息字段名, 默认message
	MessageField string `toml:"message_field" json:"message_field" yaml:"message_field"  env:"MESSAGE_FIELD"`
	// 开启Trace时, 记录的TraceId名称, 默认trace_id
	TraceFiled string `toml:"trace_filed" json:"trace_filed" yaml:"trace_filed"  env:"TRACE_FILED"`
	// 应用分组名称, 默认group
	AppGroupFiled string `toml:"app_group_filed" json:"app_group_filed" yaml:"app_group_filed"  env:"APP_GROUP_FILED"`
	// 应用名称, 默认为app
	AppNameFiled string `toml:"app_name_filed" json:"app_name_filed" yaml:"app_name_filed"  env:"APP_NAME_FILED"`
	// 主机名称, 默认hostname
	HostnameFiled string `toml:"hostname_filed" json:"hostname_filed" yaml:"hostname_filed"  env:"HOSTNAME_FILED"`
	// 额外的字段
	ExtraFileds map[string]string `toml:"extra_fields" json:"extra_fields" yaml:"extra_fields" envPrefix:"EXTRA_"`

	// 控制台日志配置
	Console Console `toml:"console" json:"console" yaml:"console" envPrefix:"CONSOLE_"`
	// 日志文件配置
	File File `toml:"file" json:"file" yaml:"file" envPrefix:"FILE_"`

	ioc.ObjectImpl
	// contains filtered or unexported fields
}

func Get added in v2.0.8

func Get() *Config

func (*Config) CallerMarshalFunc

func (m *Config) CallerMarshalFunc(pc uintptr, file string, line int) string

func (*Config) Init

func (m *Config) Init() error

func (*Config) IsMyLogger added in v2.0.77

func (m *Config) IsMyLogger(logger *zerolog.Logger) bool

func (*Config) Logger

func (m *Config) Logger(name string) *zerolog.Logger

func (*Config) Name

func (m *Config) Name() string

func (*Config) Priority

func (i *Config) Priority() int

Trace加载后才加载日志

func (*Config) SetRoot

func (m *Config) SetRoot(r zerolog.Logger)

type Console

type Console struct {
	Enable  bool `toml:"enable" json:"enable" yaml:"enable"  env:"ENABLE"`
	NoColor bool `toml:"no_color" json:"no_color" yaml:"no_color"  env:"NO_COLOR"`
}

func (*Console) ConsoleWriter

func (c *Console) ConsoleWriter() io.Writer

type File

type File struct {
	// 是否开启文件记录
	Enable bool `toml:"enable" json:"enable" yaml:"enable"  env:"ENABLE"`
	// 日志目录路径
	DirPath string `toml:"dir_path" json:"dir_path" yaml:"dir_path"  env:"DIR_PATH"`
	// 单位M, 默认100M
	MaxSize int `toml:"max_size" json:"max_size" yaml:"max_size"  env:"MAX_SIZE"`
	// 默认保存 6个文件
	MaxBackups int `toml:"max_backups" json:"max_backups" yaml:"max_backups"  env:"MAX_BACKUPS"`
	// 保存多久
	MaxAge int `toml:"max_age" json:"max_age" yaml:"max_age"  env:"MAX_AGE"`
	// 是否压缩
	Compress bool `toml:"compress" json:"compress" yaml:"compress"  env:"COMPRESS"`
}

func (*File) FileWriter

func (f *File) FileWriter(appLogFileName string) io.Writer

Jump to

Keyboard shortcuts

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