Skip to content
This repository has been archived by the owner on Feb 27, 2023. It is now read-only.

Commit

Permalink
Configure logfile path via 'logConfig.path' property
Browse files Browse the repository at this point in the history
Signed-off-by: YanzheL <[email protected]>
  • Loading branch information
YanzheL committed Jan 14, 2020
1 parent def2b21 commit bf81246
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
6 changes: 2 additions & 4 deletions cmd/dfdaemon/app/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,13 @@ func initLogger(cfg config.Properties) error {
cfg.WorkHome = filepath.Join(current.HomeDir, ".small-dragonfly")
}

logFilePath := filepath.Join(cfg.WorkHome, "logs", "dfdaemon.log")

opts := []dflog.Option{
dflog.WithLogFile(logFilePath, cfg.LogConfig.MaxSize, cfg.LogConfig.MaxBackups),
dflog.WithLogFile(cfg.LogConfig.Path, cfg.LogConfig.MaxSize, cfg.LogConfig.MaxBackups),
dflog.WithSign(fmt.Sprintf("%d", os.Getpid())),
dflog.WithDebug(cfg.Verbose),
}

logrus.Debugf("use log file %s", logFilePath)
logrus.Debugf("use log file %s", cfg.LogConfig.Path)

return errors.Wrap(dflog.Init(logrus.StandardLogger(), opts...), "init log")
}
Expand Down
7 changes: 6 additions & 1 deletion pkg/dflog/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"bytes"
"fmt"
"os"
"path/filepath"
"strings"

"github.com/pkg/errors"
Expand All @@ -35,6 +36,10 @@ type LogConfig struct {
// MaxBackups is the maximum number of old log files to retain.
// The default value is 1.
MaxBackups int `yaml:"maxBackups" json:"maxBackups"`

// Path is the location of log file
// The default value is logs/dfdaemon.log
Path string `yaml:"path" json:"path"`
}

// DefaultLogTimeFormat defines the timestamp format.
Expand Down Expand Up @@ -72,7 +77,7 @@ func getLumberjack(l *logrus.Logger) *lumberjack.Logger {
func WithLogFile(f string, maxSize, maxBackups int) Option {
return func(l *logrus.Logger) error {
if f == "" {
return nil
f = filepath.Join("logs", "dfdaemon.log")
}
if maxSize <= 0 {
maxSize = 40
Expand Down

0 comments on commit bf81246

Please sign in to comment.