Skip to content

Commit ecf2994

Browse files
bug: still use default logger with regular user (#394)
the default logrus hook should be used, even when running as a regular user.
1 parent 4090f21 commit ecf2994

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

pkg/logging/logging.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package logging
55

66
import (
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.
5558
func 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.
105103
func SetupLogging() {
106104
if !needsFileLogging() {
105+
logrus.SetOutput(io.Discard)
106+
logrus.AddHook(&StdoutLogger{})
107107
return
108108
}
109109
logrus.SetLevel(logrus.DebugLevel)

0 commit comments

Comments
 (0)