File tree Expand file tree Collapse file tree 1 file changed +6
-6
lines changed Expand file tree Collapse file tree 1 file changed +6
-6
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ package logging
55
66import (
77 "fmt"
8+ "io"
89 "os"
910 "strings"
1011 "time"
@@ -52,6 +53,8 @@ func (hook *StdoutLogger) Fire(entry *logrus.Entry) error {
5253}
5354
5455// needsFileLogging filters out, based on command line argument, if we need to log to a file.
56+ // we only log to a file when running as root as the log location is in a directory a regular
57+ // user may not be able to write to.
5558func needsFileLogging () bool {
5659 if len (os .Args ) == 1 {
5760 return false
@@ -66,12 +69,7 @@ func needsFileLogging() bool {
6669 if strings .Contains (cmdline , "shell" ) {
6770 return false
6871 }
69- if os .Getuid () != 0 {
70- // if this is not the root user, we're going to exit with a 'you aren't root' error
71- return false
72- }
73-
74- return true
72+ return os .Getuid () == 0
7573}
7674
7775// trimLogDir removes the oldest log files if we have more than MaxLogFiles.
@@ -104,6 +102,8 @@ func trimLogDir() {
104102// all to the screen otherwise we print to a log file.
105103func SetupLogging () {
106104 if ! needsFileLogging () {
105+ logrus .SetOutput (io .Discard )
106+ logrus .AddHook (& StdoutLogger {})
107107 return
108108 }
109109 logrus .SetLevel (logrus .DebugLevel )
You can’t perform that action at this time.
0 commit comments