Skip to content

Commit

Permalink
optimize: logger
Browse files Browse the repository at this point in the history
  • Loading branch information
mzz2017 committed Sep 18, 2024
1 parent 1d3f903 commit c3c06c4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
5 changes: 3 additions & 2 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,9 @@ var (
Compress: true,
}
}
log := logger.NewLogger(conf.Global.LogLevel, disableTimestamp, logOpts)
logrus.SetLevel(log.Level)
log := logrus.New()
logger.SetLogger(log, conf.Global.LogLevel, disableTimestamp, logOpts)
logger.SetLogger(logrus.StandardLogger(), conf.Global.LogLevel, disableTimestamp, logOpts)

log.Infof("Include config files: [%v]", strings.Join(includes, ", "))
if err := Run(log, conf, []string{filepath.Dir(cfgFile)}); err != nil {
Expand Down
6 changes: 1 addition & 5 deletions pkg/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ import (
"gopkg.in/natefinch/lumberjack.v2"
)

func NewLogger(logLevel string, disableTimestamp bool, logFileOpt *lumberjack.Logger) *logrus.Logger {
log := logrus.New()

func SetLogger(log *logrus.Logger, logLevel string, disableTimestamp bool, logFileOpt *lumberjack.Logger) {
level, err := logrus.ParseLevel(logLevel)
if err != nil {
level = logrus.InfoLevel
Expand All @@ -28,6 +26,4 @@ func NewLogger(logLevel string, disableTimestamp bool, logFileOpt *lumberjack.Lo
if logFileOpt != nil {
log.SetOutput(logFileOpt)
}

return log
}

0 comments on commit c3c06c4

Please sign in to comment.