Skip to content
This repository was archived by the owner on Dec 20, 2024. It is now read-only.

Commit bf81246

Browse files
committed
Configure logfile path via 'logConfig.path' property
Signed-off-by: YanzheL <[email protected]>
1 parent def2b21 commit bf81246

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

cmd/dfdaemon/app/init.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,13 @@ func initLogger(cfg config.Properties) error {
8080
cfg.WorkHome = filepath.Join(current.HomeDir, ".small-dragonfly")
8181
}
8282

83-
logFilePath := filepath.Join(cfg.WorkHome, "logs", "dfdaemon.log")
84-
8583
opts := []dflog.Option{
86-
dflog.WithLogFile(logFilePath, cfg.LogConfig.MaxSize, cfg.LogConfig.MaxBackups),
84+
dflog.WithLogFile(cfg.LogConfig.Path, cfg.LogConfig.MaxSize, cfg.LogConfig.MaxBackups),
8785
dflog.WithSign(fmt.Sprintf("%d", os.Getpid())),
8886
dflog.WithDebug(cfg.Verbose),
8987
}
9088

91-
logrus.Debugf("use log file %s", logFilePath)
89+
logrus.Debugf("use log file %s", cfg.LogConfig.Path)
9290

9391
return errors.Wrap(dflog.Init(logrus.StandardLogger(), opts...), "init log")
9492
}

pkg/dflog/log.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"bytes"
2121
"fmt"
2222
"os"
23+
"path/filepath"
2324
"strings"
2425

2526
"github.com/pkg/errors"
@@ -35,6 +36,10 @@ type LogConfig struct {
3536
// MaxBackups is the maximum number of old log files to retain.
3637
// The default value is 1.
3738
MaxBackups int `yaml:"maxBackups" json:"maxBackups"`
39+
40+
// Path is the location of log file
41+
// The default value is logs/dfdaemon.log
42+
Path string `yaml:"path" json:"path"`
3843
}
3944

4045
// DefaultLogTimeFormat defines the timestamp format.
@@ -72,7 +77,7 @@ func getLumberjack(l *logrus.Logger) *lumberjack.Logger {
7277
func WithLogFile(f string, maxSize, maxBackups int) Option {
7378
return func(l *logrus.Logger) error {
7479
if f == "" {
75-
return nil
80+
f = filepath.Join("logs", "dfdaemon.log")
7681
}
7782
if maxSize <= 0 {
7883
maxSize = 40

0 commit comments

Comments
 (0)