diff --git a/glog.go b/glog.go index c5c4361e8..982e7b8a5 100644 --- a/glog.go +++ b/glog.go @@ -574,9 +574,9 @@ func (l *loggingT) formatHeader(s severity, file string, line int) *buffer { buf.tmp[14] = '.' buf.nDigits(6, 15, now.Nanosecond()/1000, '0') buf.tmp[21] = ' ' - buf.nDigits(5, 22, pid, ' ') // TODO: should be TID - buf.tmp[27] = ' ' - buf.Write(buf.tmp[:28]) + buf.nDigits(7, 22, pid, ' ') // TODO: should be TID + buf.tmp[29] = ' ' + buf.Write(buf.tmp[:30]) buf.WriteString(file) buf.tmp[0] = ':' n := buf.someDigits(1, line) diff --git a/glog_test.go b/glog_test.go index 90194fdc6..0fb376e1f 100644 --- a/glog_test.go +++ b/glog_test.go @@ -180,10 +180,17 @@ func TestHeader(t *testing.T) { pid = 1234 Info("test") var line int - n, err := fmt.Sscanf(contents(infoLog), "I0102 15:04:05.067890 1234 glog_test.go:%d] test\n", &line) + format := "I0102 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)) } + // Scanf treats multiple spaces as equivalent to a single space, + // so check for correct space-padding also. + want := fmt.Sprintf(format, line) + if contents(infoLog) != want { + t.Errorf("log format error: got:\n\t%q\nwant:\t%q", contents(infoLog), want) + } } // Test that an Error log goes to Warning and Info.