Skip to content

Commit

Permalink
Fix problem that -log_dir will not be respected when anything is logg…
Browse files Browse the repository at this point in the history
…ed 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.
  • Loading branch information
michael-berlin committed Jul 24, 2015
1 parent 44145f0 commit 65d6746
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion glog.go
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,10 @@ func (l *loggingT) output(s severity, buf *buffer, file string, line int, alsoTo
}
}
data := buf.Bytes()
if l.toStderr {
if !flag.Parsed() {
os.Stderr.Write([]byte("ERROR: logging before flag.Parse: "))
os.Stderr.Write(data)
} else if l.toStderr {
os.Stderr.Write(data)
} else {
if alsoToStderr || l.alsoToStderr || s >= l.stderrThreshold.get() {
Expand Down

0 comments on commit 65d6746

Please sign in to comment.