Skip to content

Commit

Permalink
feat(conf): 为配置项添加日志文件自定义名称
Browse files Browse the repository at this point in the history
  • Loading branch information
sunist-c committed Sep 12, 2024
1 parent 905410d commit f16c1f5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
9 changes: 5 additions & 4 deletions app/global/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ type BloomFilterConfig struct {
}

type LogConfig struct {
LogToFile bool `yaml:"log_to_file"`
LogSplit bool `yaml:"log_split"`
LogDirectory string `yaml:"log_directory"`
LogLevel string `yaml:"log_level"`
LogToFile bool `yaml:"log_to_file"`
LogSplit bool `yaml:"log_split"`
LogDirectory string `yaml:"log_directory"`
LogLevel string `yaml:"log_level"`
LogFileSuffix string `yaml:"log_file_suffix"`
}

type AppConfig struct {
Expand Down
7 changes: 5 additions & 2 deletions app/global/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ func initializeConfig() {
}

func initializeLogger() {
if Config.Logger.LogFileSuffix == "" {
Config.Logger.LogFileSuffix = "_akasha_whisper_logs_stdout.jsonl"
}
switch {
case !Config.Logger.LogToFile:
Logger = logger.NewCustomLoggerWithOpts(
Expand All @@ -61,14 +64,14 @@ func initializeLogger() {
case !Config.Logger.LogSplit:
Logger = logger.NewCustomLoggerWithOpts(
logger.WithLevelOpts(logger.Level(Config.Logger.LogLevel)),
logger.WithFileWriterOpts(filepath.Join(Config.Logger.LogDirectory, "akasha_whisper_log.jsonl")),
logger.WithFileWriterOpts(filepath.Join(Config.Logger.LogDirectory, Config.Logger.LogFileSuffix)),
)
default:
Logger = logger.NewCustomLoggerWithOpts(
logger.WithLevelOpts(logger.Level(Config.Logger.LogLevel)),
logger.WithCustomWriterOpts(
logger.NewTimeBasedRotationFileWriter(Config.Logger.LogDirectory, func(time time.Time) (filename string) {
return values.BuildStrings(time.Format("2006-01-02"), "_akasha_whisper_log.jsonl")
return values.BuildStrings(time.Format("2006-01-02"), Config.Logger.LogFileSuffix)
}),
),
)
Expand Down
3 changes: 2 additions & 1 deletion config/config.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ http_engine:
enable_management_apis: true # enable management apis, if set to false or unset, management apis will not serve
logger:
log_to_file: true # log to file, set to false means log to stdout
log_split: true # split log file by day
log_split: true # split log file by day, log file name will be like '2021-01-01_akasha_whisper_logs_stdout.jsonl'
log_directory: './log' # log directory, must be created before starting, or it will panic the program
log_level: 'info' # enum: debug, info, warn, error, panic, fatal
log_file_suffix: '_stdout.jsonl' # log file suffix, must start with '_' and end with extension, default is '_akasha_whisper_logs_stdout.jsonl'
bloom_filter:
enable: true # enable bloom filter
filter_size: 1000000 # bloom filter size
Expand Down

0 comments on commit f16c1f5

Please sign in to comment.