From 65d674618f712aa808a7d0104131b9206fc3d5ad Mon Sep 17 00:00:00 2001 From: Michael Berlin Date: Fri, 24 Jul 2015 16:44:32 -0700 Subject: [PATCH] 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. --- glog.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/glog.go b/glog.go index 3e63fffd5..54bd7afdc 100644 --- a/glog.go +++ b/glog.go @@ -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() {