Skip to content

Add the year to the glog header #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions glog.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion glog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down