Pad thread ID in log header to 7 spaces, to match C++ format.
Add check in TestHeader to detect padding mismatch.
diff --git a/glog.go b/glog.go
index c5c4361..982e7b8 100644
--- a/glog.go
+++ b/glog.go
@@ -574,9 +574,9 @@
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 90194fd..0fb376e 100644
--- a/glog_test.go
+++ b/glog_test.go
@@ -180,10 +180,17 @@
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.