소스 검색

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.
Michael Berlin 10 년 전
부모
커밋
65d674618f
1개의 변경된 파일4개의 추가작업 그리고 1개의 파일을 삭제
  1. 4 1
      glog.go

+ 4 - 1
glog.go

@@ -676,7 +676,10 @@ func (l *loggingT) output(s severity, buf *buffer, file string, line int, alsoTo
 		}
 		}
 	}
 	}
 	data := buf.Bytes()
 	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)
 		os.Stderr.Write(data)
 	} else {
 	} else {
 		if alsoToStderr || l.alsoToStderr || s >= l.stderrThreshold.get() {
 		if alsoToStderr || l.alsoToStderr || s >= l.stderrThreshold.get() {