-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
38 lines (32 loc) · 1.04 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package log
import (
"time"
"github.com/no-src/log/level"
"github.com/no-src/log/option"
)
type config struct {
Loggers []loggerConfig `yaml:"loggers"`
}
type loggerConfig struct {
// common fields
Name string `yaml:"name"`
Type string `yaml:"type"`
Level string `yaml:"level"`
Format string `yaml:"format"`
TimeFormat string `yaml:"time-format"`
Sample float64 `yaml:"sample"`
// file logger fields
LogDir string `yaml:"log-dir"`
LogFilePrefix string `yaml:"log-file-prefix"`
AutoFlush bool `yaml:"auto-flush"`
AutoFlushInterval time.Duration `yaml:"auto-flush-interval"`
SplitByDate bool `yaml:"split-by-date"`
}
func toFileLoggerOption(logConf loggerConfig) (opt option.FileLoggerOption, err error) {
lvl, err := level.ParseLevel(logConf.Level)
if err != nil {
return opt, err
}
opt = option.NewFileLoggerOption(lvl, logConf.LogDir, logConf.LogFilePrefix, logConf.AutoFlush, logConf.AutoFlushInterval, logConf.SplitByDate)
return opt, nil
}