From 43fe389af3bd38be08ababc799f102f9d785f0f8 Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Thu, 1 Sep 2016 22:13:48 +0200 Subject: [PATCH] Redirect stdout and stderr to logfile Makes it harder to loose panic messages --- modules/log/file.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/modules/log/file.go b/modules/log/file.go index e9402815f..03390d458 100644 --- a/modules/log/file.go +++ b/modules/log/file.go @@ -14,6 +14,7 @@ import ( "path/filepath" "strings" "sync" + "syscall" "time" ) @@ -113,6 +114,10 @@ func (w *FileLogWriter) StartLogger() error { if err = w.initFd(); err != nil { return err } + // redirect stdout and stderr to file + // TODO: allow specifying in configuration ? + syscall.Dup2(int(fd.Fd()), 1) // stdout + syscall.Dup2(int(fd.Fd()), 2) // stderr return nil }