diff --git a/glog.go b/glog.go index 595b8fa4c..01bd44770 100644 --- a/glog.go +++ b/glog.go @@ -583,24 +583,25 @@ func (l *loggingT) formatHeader(s severity, file string, line int) *buffer { // Avoid Fprintf, for speed. The format is so simple that we can do it quickly by hand. // It's worth about 3X. Fprintf is hard. - _, month, day := now.Date() + year, month, day := now.Date() hour, minute, second := now.Clock() - // Lmmdd hh:mm:ss.uuuuuu threadid file:line] + // Lyyyymmdd hh:mm:ss.uuuuuu threadid file:line] buf.tmp[0] = severityChar[s] - buf.twoDigits(1, int(month)) - buf.twoDigits(3, day) - buf.tmp[5] = ' ' - buf.twoDigits(6, hour) - buf.tmp[8] = ':' - buf.twoDigits(9, minute) - buf.tmp[11] = ':' - buf.twoDigits(12, second) - buf.tmp[14] = '.' - buf.nDigits(6, 15, now.Nanosecond()/1000, '0') - buf.tmp[21] = ' ' - buf.nDigits(7, 22, pid, ' ') // TODO: should be TID - buf.tmp[29] = ' ' - buf.Write(buf.tmp[:30]) + buf.nDigits(4, 1, year, '0') + buf.twoDigits(5, int(month)) + buf.twoDigits(7, day) + buf.tmp[9] = ' ' + buf.twoDigits(10, hour) + buf.tmp[12] = ':' + buf.twoDigits(13, minute) + buf.tmp[15] = ':' + buf.twoDigits(16, second) + buf.tmp[18] = '.' + buf.nDigits(6, 19, now.Nanosecond()/1000, '0') + buf.tmp[25] = ' ' + buf.nDigits(7, 26, pid, ' ') // TODO: should be TID + buf.tmp[33] = ' ' + buf.Write(buf.tmp[:34]) buf.WriteString(file) buf.tmp[0] = ':' n := buf.someDigits(1, line) diff --git a/glog_test.go b/glog_test.go index 64a892ee4..44c96a6b3 100644 --- a/glog_test.go +++ b/glog_test.go @@ -180,7 +180,7 @@ func TestHeader(t *testing.T) { pid = 1234 Info("test") var line int - format := "I0102 15:04:05.067890 1234 glog_test.go:%d] test\n" + format := "I20060102 15:04:05.067890 1234 glog_test.go:%d] test\n" n, err := fmt.Sscanf(contents(infoLog), format, &line) if n != 1 || err != nil { t.Errorf("log format error: %d elements, error %s:\n%s", n, err, contents(infoLog))