-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathentry.go
68 lines (59 loc) · 1.2 KB
/
entry.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package golog
import (
"context"
)
// Entry is a log entry
type Entry interface {
Level() Level
Message() Message
Fields() Fields
Context() context.Context
With(...Field) Entry
}
// StdEntry is a representation of the standard log Entry
type StdEntry struct {
Ctx context.Context
Lvl Level
Msg Message
Flds Fields
}
// NewStdEntry returns a StdEntry
func NewStdEntry(
ctx context.Context,
lvl Level,
msg string,
flds Fields,
) StdEntry {
return StdEntry{
Ctx: ctx,
Lvl: lvl,
Msg: msg,
Flds: flds,
}
}
// Context returns an entry assigned to the entry
// This could be used to enrich the entry after it get created for the first time
func (e StdEntry) Context() context.Context {
return e.Ctx
}
// Level returns the entry Level
func (e StdEntry) Level() Level {
return e.Lvl
}
// Message returns the entry Message
func (e StdEntry) Message() Message {
return e.Msg
}
// Fields returns the fields assigned to a log entry
func (e StdEntry) Fields() Fields {
return e.Flds
}
// With returns a new StdEntry appending the given extra Fields
func (e StdEntry) With(flds ...Field) Entry {
return StdEntry{
Lvl: e.Lvl,
Msg: e.Msg,
Flds: append(e.Flds, flds...),
Ctx: e.Ctx,
}
}