log

package
v1.2.7 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: MIT Imports: 9 Imported by: 1

Documentation

Index

Constants

View Source
const (
	AppName        = "log"
	SUB_LOGGER_KEY = "component"
)

Variables

This section is empty.

Functions

func L

func L() *zerolog.Logger

没有key:value 直接调用直走init

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:"LOG_CALLER_DEEP"`
	// 日志的级别, 默认Debug
	Level zerolog.Level `toml:"level" json:"level" yaml:"level"  env:"LOG_LEVEL"`
	// 开启Trace时, 记录的TraceId名称, 默认trace_id
	TraceFiled string `toml:"trace_filed" json:"trace_filed" yaml:"trace_filed"  env:"LOG_TRACE_FILED"`

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

	ioc.ObjectImpl
	// contains filtered or unexported fields
}

func (*Config) CallerMarshalFunc

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

这是一个函数,用于格式化调用者信息。 通过将配置对象 c 中的 CallerMarshalFunc 赋值给全局变量,可以自定义调用者信息的格式化方式

func (*Config) Init

func (c *Config) Init() error

注册时版本初始化覆盖ioc.ObjectImpl

func (*Config) Logger

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

这个可以在init里面做

func (*Config) Name

func (c *Config) Name() string

func (*Config) Priority

func (i *Config) Priority() int

func (*Config) SetRoot

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

func (*Config) TraceLogger

func (c *Config) TraceLogger(name string) *TraceLogger

开启Trace时, 记录的TraceId名称

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

设置日志打印在console上 在这里,i interface{} 是一个空接口类型,表示可以接受任意类型的值。 在 FormatLevel、FormatMessage、FormatFieldName、FormatFieldValue 四个函数中 i 表示相应的字段值,但具体的类型会根据日志库的实现和日志记录时传递的值而变化。这种设计允许日志库接受各种类型的字段,并使用用户提供的函数来格式化这些字段的输出

type File

type File struct {
	// 是否开启文件记录
	Enable bool `toml:"enable" json:"enable" yaml:"enable"  env:"ENABLE"`
	// 文件的路径
	FilePath string `toml:"file_path" json:"file_path" yaml:"file_path"  env:"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() io.Writer

type TraceLogger

type TraceLogger struct {
	// contains filtered or unexported fields
}

func T

func T(name string) *TraceLogger

Jump to

Keyboard shortcuts

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