Skip to content

Commit 65d6746

Browse files
Fix problem that -log_dir will not be respected when anything is logged before flag.Parse().
Before this change, premature logging resulted into log files being put in the default location (e.g. /tmp), but not the one specified by the log_dir flag. After this change, premature logging will not result into the creation of the log files yet. Instead, the log message will be printed to stderr.
1 parent 44145f0 commit 65d6746

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

glog.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,10 @@ func (l *loggingT) output(s severity, buf *buffer, file string, line int, alsoTo
676676
}
677677
}
678678
data := buf.Bytes()
679-
if l.toStderr {
679+
if !flag.Parsed() {
680+
os.Stderr.Write([]byte("ERROR: logging before flag.Parse: "))
681+
os.Stderr.Write(data)
682+
} else if l.toStderr {
680683
os.Stderr.Write(data)
681684
} else {
682685
if alsoToStderr || l.alsoToStderr || s >= l.stderrThreshold.get() {

0 commit comments

Comments
 (0)