Skip to content

Commit c2be0ef

Browse files
author
Dean Karn
committed
fix setting the Timestamp in correct spot
1 parent b57928e commit c2be0ef

File tree

3 files changed

+7
-12
lines changed

3 files changed

+7
-12
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
## log
2-
<img align="right" src="https://raw.githubusercontent.com/go-playground/log/master/logo.png">![Project status](https://img.shields.io/badge/version-5.0.1-green.svg)
2+
<img align="right" src="https://raw.githubusercontent.com/go-playground/log/master/logo.png">![Project status](https://img.shields.io/badge/version-5.0.2-green.svg)
33
[![Build Status](https://semaphoreci.com/api/v1/joeybloggs/log/branches/master/badge.svg)](https://semaphoreci.com/joeybloggs/log)
44
[![Coverage Status](https://coveralls.io/repos/github/go-playground/log/badge.svg?branch=master)](https://coveralls.io/github/go-playground/log?branch=master)
55
[![Go Report Card](https://goreportcard.com/badge/github.com/go-playground/log)](https://goreportcard.com/report/github.com/go-playground/log)

entry.go

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,14 @@ type Entry struct {
2121
}
2222

2323
func newEntry(e Entry) Entry {
24-
ne := Entry{
25-
Fields: make([]Field, 0, len(e.Fields)),
26-
Timestamp: time.Now(),
27-
Message: e.Message,
28-
Level: e.Level,
29-
start: e.start,
30-
}
31-
ne.Fields = append(ne.Fields, e.Fields...)
32-
return ne
24+
flds := make([]Field, 0, len(e.Fields))
25+
e.Fields = append(flds, e.Fields...)
26+
return e
3327
}
3428

3529
func newEntryWithFields(fields []Field) Entry {
3630
e := Entry{
37-
Fields: make([]Field, 0, len(fields)),
38-
Timestamp: time.Now(),
31+
Fields: make([]Field, 0, len(fields)),
3932
}
4033
e.Fields = append(e.Fields, fields...)
4134
return e

log.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ func handleEntry(e Entry) {
5656
if !e.start.IsZero() {
5757
e = e.WithField("duration", time.Since(e.start))
5858
}
59+
e.Timestamp = time.Now()
60+
5961
for _, h := range logHandlers[e.Level] {
6062
h.Log(e)
6163
}

0 commit comments

Comments
 (0)