mirror of
https://gitee.ltd/lxh/logger.git
synced 2025-10-23 14:56:16 +08:00
🎉logger的v2版本,暂未支持环境变量配置
This commit is contained in:
118
option.go
Normal file
118
option.go
Normal file
@@ -0,0 +1,118 @@
|
||||
package zap_logger
|
||||
|
||||
type Encoder string
|
||||
|
||||
const (
|
||||
JsonEncoder Encoder = "json"
|
||||
ConsoleEncoder Encoder = "console"
|
||||
)
|
||||
|
||||
type Option func(conf *Config)
|
||||
|
||||
func WithEncoder(encoder Encoder) Option {
|
||||
return func(conf *Config) {
|
||||
conf.Logger.Encoder = string(encoder)
|
||||
}
|
||||
}
|
||||
|
||||
func WithLevel(level string) Option {
|
||||
return func(conf *Config) {
|
||||
conf.Logger.Level = level
|
||||
}
|
||||
}
|
||||
|
||||
func WithEnableFile(enable bool) Option {
|
||||
return func(conf *Config) {
|
||||
conf.File.Enable = enable
|
||||
}
|
||||
}
|
||||
|
||||
func WithFilename(filename string) Option {
|
||||
return func(conf *Config) {
|
||||
conf.File.Filename = filename
|
||||
}
|
||||
}
|
||||
|
||||
func WithFileMaxSize(maxSize int) Option {
|
||||
return func(conf *Config) {
|
||||
conf.File.MaxSize = maxSize
|
||||
}
|
||||
}
|
||||
|
||||
func WithFileMaxAge(maxAge int) Option {
|
||||
return func(conf *Config) {
|
||||
conf.File.MaxAge = maxAge
|
||||
}
|
||||
}
|
||||
|
||||
func WithFileMaxBackups(maxBackups int) Option {
|
||||
return func(conf *Config) {
|
||||
conf.File.MaxBackups = maxBackups
|
||||
}
|
||||
}
|
||||
|
||||
func WithFileLocaltime(localtime bool) Option {
|
||||
return func(conf *Config) {
|
||||
conf.File.LocalTime = localtime
|
||||
}
|
||||
}
|
||||
|
||||
func WithFileCompress(compress bool) Option {
|
||||
return func(conf *Config) {
|
||||
conf.File.Compress = compress
|
||||
}
|
||||
}
|
||||
|
||||
func WithConsoleEnable(enable bool) Option {
|
||||
return func(conf *Config) {
|
||||
conf.Console.Enable = enable
|
||||
}
|
||||
}
|
||||
|
||||
func WithConsoleEnableColor(color bool) Option {
|
||||
return func(conf *Config) {
|
||||
conf.Console.Color = color
|
||||
}
|
||||
}
|
||||
|
||||
func WithLokiEnable(enable bool) Option {
|
||||
return func(conf *Config) {
|
||||
conf.Loki.Enable = enable
|
||||
}
|
||||
}
|
||||
|
||||
func WithLokiHost(host string) Option {
|
||||
return func(conf *Config) {
|
||||
conf.Loki.Host = host
|
||||
}
|
||||
}
|
||||
|
||||
func WithLokiPort(port int) Option {
|
||||
return func(conf *Config) {
|
||||
conf.Loki.Port = port
|
||||
}
|
||||
}
|
||||
|
||||
func WithLokiSource(source string) Option {
|
||||
return func(conf *Config) {
|
||||
conf.Loki.Source = source
|
||||
}
|
||||
}
|
||||
|
||||
func WithLokiService(service string) Option {
|
||||
return func(conf *Config) {
|
||||
conf.Loki.Service = service
|
||||
}
|
||||
}
|
||||
|
||||
func WithLokiJob(job string) Option {
|
||||
return func(conf *Config) {
|
||||
conf.Loki.Job = job
|
||||
}
|
||||
}
|
||||
|
||||
func WithLokiEnvironment(environment string) Option {
|
||||
return func(conf *Config) {
|
||||
conf.Loki.Environment = environment
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user