github.com/ronaksoft/rony@v0.16.26-0.20230807065236-1743dbfe6959/log/config.go (about)

     1  package log
     2  
     3  import "go.uber.org/zap/zapcore"
     4  
     5  type Option func(cfg *config)
     6  
     7  type config struct {
     8  	level           Level
     9  	TimeEncoder     TimeEncoder
    10  	LevelEncoder    LevelEncoder
    11  	DurationEncoder DurationEncoder
    12  	CallerEncoder   CallerEncode
    13  	sentryDSN       string
    14  	sentryLevel     Level
    15  	release         string
    16  	environment     string
    17  	skipCaller      int
    18  	syslogTag       string
    19  }
    20  
    21  var defaultConfig = config{
    22  	level:           InfoLevel,
    23  	sentryDSN:       "",
    24  	sentryLevel:     WarnLevel,
    25  	release:         "",
    26  	environment:     "",
    27  	skipCaller:      1,
    28  	TimeEncoder:     timeEncoder,
    29  	LevelEncoder:    zapcore.CapitalLevelEncoder,
    30  	DurationEncoder: zapcore.StringDurationEncoder,
    31  	CallerEncoder:   zapcore.ShortCallerEncoder,
    32  }
    33  
    34  func WithLevel(lvl Level) Option {
    35  	return func(cfg *config) {
    36  		cfg.level = lvl
    37  	}
    38  }
    39  
    40  func WithRelease(version string) Option {
    41  	return func(cfg *config) {
    42  		cfg.release = version
    43  	}
    44  }
    45  
    46  func WithEnvironment(env string) Option {
    47  	return func(cfg *config) {
    48  		cfg.environment = env
    49  	}
    50  }
    51  
    52  func WithSkipCaller(skip int) Option {
    53  	return func(cfg *config) {
    54  		cfg.skipCaller = skip
    55  	}
    56  }
    57  
    58  func WithSentry(dsn string, lvl Level) Option {
    59  	return func(cfg *config) {
    60  		cfg.sentryDSN = dsn
    61  		cfg.sentryLevel = lvl
    62  	}
    63  }
    64  
    65  func WithSyslog(tag string) Option {
    66  	return func(cfg *config) {
    67  		cfg.syslogTag = tag
    68  	}
    69  }
    70  
    71  func WithMongoDB(dsn string) Option {
    72  	return func(cfg *config) {
    73  
    74  	}
    75  }