Skip to content

Commit

Permalink
chore: when console log enabled, skip daemon redirect stdout
Browse files Browse the repository at this point in the history
Signed-off-by: Jim Ma <[email protected]>
  • Loading branch information
jim3ma committed Apr 14, 2022
1 parent f9592fb commit 613b059
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions cmd/dfget/cmd/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ it supports container engine, wget and other downloading tools through proxy fun
return errors.Wrap(err, "init client daemon logger")
}

redirectStdoutAndStderr(d.LogDir())
redirectStdoutAndStderr(cfg.Console, d.LogDir())

// Convert config
if err := cfg.Convert(); err != nil {
Expand All @@ -84,12 +84,14 @@ it supports container engine, wget and other downloading tools through proxy fun

// daemon will be launched by dfget command
// redirect stdout and stderr to file for debugging
func redirectStdoutAndStderr(logDir string) {
stdoutPath := path.Join(logDir, "stdout.log")
if stdout, err := os.OpenFile(stdoutPath, os.O_WRONLY|os.O_CREATE|os.O_APPEND|os.O_SYNC, 0644); err != nil {
logger.Warnf("open %s error: %s", stdoutPath, err)
} else if err := syscall.Dup2(int(stdout.Fd()), 1); err != nil {
logger.Warnf("redirect stdout error: %s", err)
func redirectStdoutAndStderr(console bool, logDir string) {
if !console {
stdoutPath := path.Join(logDir, "stdout.log")
if stdout, err := os.OpenFile(stdoutPath, os.O_WRONLY|os.O_CREATE|os.O_APPEND|os.O_SYNC, 0644); err != nil {
logger.Warnf("open %s error: %s", stdoutPath, err)
} else if err := syscall.Dup2(int(stdout.Fd()), 1); err != nil {
logger.Warnf("redirect stdout error: %s", err)
}
}
stderrPath := path.Join(logDir, "stderr.log")
if stderr, err := os.OpenFile(stderrPath, os.O_WRONLY|os.O_CREATE|os.O_APPEND|os.O_SYNC, 0644); err != nil {
Expand Down

0 comments on commit 613b059

Please sign in to comment.