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

Commit

Permalink
Merge pull request #1145 from YanzheL/configurable-logfile-path
Browse files Browse the repository at this point in the history
Configure dfclient/dfdaemon/dfget log file path via 'logConfig.path' property
  • Loading branch information
lowzj committed Jan 16, 2020
2 parents 5ad6eb3 + c02b0b0 commit cbb4d50
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 10 deletions.
10 changes: 5 additions & 5 deletions cmd/dfdaemon/app/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,16 @@ func initLogger(cfg config.Properties) error {
}
cfg.WorkHome = filepath.Join(current.HomeDir, ".small-dragonfly")
}

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

if cfg.LogConfig.Path == "" {
cfg.LogConfig.Path = 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
6 changes: 4 additions & 2 deletions cmd/dfget/app/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,12 @@ func initProperties() ([]*propertiesResult, error) {
// while console log will output the dfget client's log in console/terminal for
// debugging usage.
func initClientLog() error {
logFilePath := filepath.Join(cfg.WorkHome, "logs", "dfclient.log")
if cfg.LogConfig.Path == "" {
cfg.LogConfig.Path = filepath.Join(cfg.WorkHome, "logs", "dfclient.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(cfg.Sign),
dflog.WithDebug(cfg.Verbose),
}
Expand Down
7 changes: 4 additions & 3 deletions cmd/dfget/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,11 @@ func runServer() error {
}

func initServerLog() error {
logFilePath := filepath.Join(cfg.WorkHome, "logs", "dfserver.log")

if cfg.LogConfig.Path == "" {
cfg.LogConfig.Path = filepath.Join(cfg.WorkHome, "logs", "dfserver.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(cfg.Sign),
dflog.WithDebug(cfg.Verbose),
}
Expand Down
5 changes: 5 additions & 0 deletions docs/config/dfdaemon_config_template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,8 @@ verbose: false

# The maximum number of CPUs that the dfdaemon can use
maxprocs: 10

# Logging
logConfig:
# Log file path
path: /dev/stdout
1 change: 1 addition & 0 deletions docs/config/dfdaemon_properties.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ The following startup parameters are supported for `dfdaemon`
| ------------- | ------------- |
| dfget_flags | dfget properties |
| dfpath | dfget bin path |
| logConfig | Logging properties |
| hijack_https | HijackHTTPS is the list of hosts whose https requests should be hijacked by dfdaemon. The first matched rule will be used |
| localrepo | Temp output dir of dfdaemon, by default `$HOME/.small-dragonfly/dfdaemon/data/` |
| proxies | Proxies is the list of rules for the transparent proxy |
Expand Down
4 changes: 4 additions & 0 deletions pkg/dflog/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,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

0 comments on commit cbb4d50

Please sign in to comment.