Skip to content
This repository was archived by the owner on Aug 17, 2025. It is now read-only.

Commit 1bb6239

Browse files
fix: remove duplicate time + timestamp (#5632)
1 parent 03bb267 commit 1bb6239

File tree

2 files changed

+14
-22
lines changed

2 files changed

+14
-22
lines changed

common/log/json.go

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ var _ Sink = (*jsonSink)(nil)
1616
type jsonEntry struct {
1717
Attributes map[string]string `json:"attributes,omitempty"`
1818
Level string `json:"level,omitempty"`
19-
Time string `json:"time,omitempty"`
2019
Error string `json:"error,omitempty"`
21-
Timestamp time.Time `json:"timestamp,omitempty"`
20+
Timestamp string `json:"timestamp,omitempty"`
2221
Sequence int `json:"sequence,omitempty"`
2322
LoggerClassName string `json:"loggerClassName,omitempty"`
2423
LoggerName string `json:"loggerName,omitempty"`
@@ -53,7 +52,7 @@ func (j *jsonSink) Log(entry Entry) error {
5352
}
5453
jentry := jsonEntry{
5554
Level: entry.Level.String(),
56-
Time: entry.Time.Format(time.RFC3339Nano),
55+
Timestamp: entry.Time.Format(time.RFC3339Nano),
5756
Error: errStr,
5857
Attributes: entry.Attributes,
5958
Message: entry.Message,
@@ -122,11 +121,13 @@ func (r *jsonEntry) ToEntry() Entry {
122121
level = Warn
123122
}
124123
}
124+
t, _ := time.Parse(time.RFC3339Nano, r.Timestamp) //nolint
125125

126126
ret := Entry{
127-
Time: r.Timestamp,
128-
Level: level,
129-
Message: r.Message,
127+
Time: t,
128+
Level: level,
129+
Message: r.Message,
130+
Attributes: r.Attributes,
130131
}
131132
if r.StackTrace != "" {
132133
ret.Message += "\n" + r.StackTrace
@@ -140,13 +141,5 @@ func (r *jsonEntry) ToEntry() Entry {
140141
} else if r.Error != "" {
141142
ret.Error = errors.New(r.Error)
142143
}
143-
144-
// Go is time, JVM is timestamp
145-
if r.Time != "" {
146-
ret.Time, err = time.Parse(time.RFC3339Nano, r.Time)
147-
if err != nil {
148-
ret.Time = time.Now()
149-
}
150-
}
151144
return ret
152145
}

common/log/logger_test.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,12 @@ func TestLogger(t *testing.T) {
2222
log.Tracef("trace: %s", "trace")
2323
log.Log(Entry{Level: Trace, Message: "trace: trace"})
2424
assert.Equal(t, strings.TrimSpace(`
25-
{"level":"trace","time":"1970-01-01T00:00:00Z","timestamp":"0001-01-01T00:00:00Z","message":"trace: trace"}
26-
{"level":"debug","time":"1970-01-01T00:00:00Z","timestamp":"0001-01-01T00:00:00Z","message":"debug: debug"}
27-
{"level":"info","time":"1970-01-01T00:00:00Z","timestamp":"0001-01-01T00:00:00Z","message":"info: info"}
28-
{"level":"warn","time":"1970-01-01T00:00:00Z","timestamp":"0001-01-01T00:00:00Z","message":"warn: warn"}
29-
{"level":"error","time":"1970-01-01T00:00:00Z","error":"error","timestamp":"0001-01-01T00:00:00Z","message":"error: error: error"}
30-
{"attributes":{"key":"value","scope":"scoped"},"level":"trace","time":"1970-01-01T00:00:00Z","timestamp":"0001-01-01T00:00:00Z","message":"trace: trace"}
31-
{"attributes":{"key":"value","scope":"scoped"},"level":"trace","time":"1970-01-01T00:00:00Z","timestamp":"0001-01-01T00:00:00Z","message":"trace: trace"}
32-
25+
{"level":"trace","timestamp":"1970-01-01T00:00:00Z","message":"trace: trace"}
26+
{"level":"debug","timestamp":"1970-01-01T00:00:00Z","message":"debug: debug"}
27+
{"level":"info","timestamp":"1970-01-01T00:00:00Z","message":"info: info"}
28+
{"level":"warn","timestamp":"1970-01-01T00:00:00Z","message":"warn: warn"}
29+
{"level":"error","error":"error","timestamp":"1970-01-01T00:00:00Z","message":"error: error: error"}
30+
{"attributes":{"key":"value","scope":"scoped"},"level":"trace","timestamp":"1970-01-01T00:00:00Z","message":"trace: trace"}
31+
{"attributes":{"key":"value","scope":"scoped"},"level":"trace","timestamp":"1970-01-01T00:00:00Z","message":"trace: trace"}
3332
`)+"\n", w.String())
3433
}

0 commit comments

Comments
 (0)