-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentry_builder.go
69 lines (57 loc) · 1.15 KB
/
entry_builder.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
69
package tower
import (
"context"
"fmt"
"time"
)
type entryBuilder struct {
code int
message string
caller Caller
context []any
key string
level Level
time time.Time
tower *Tower
}
func (e *entryBuilder) Code(i int) EntryBuilder {
e.code = i
return e
}
func (e *entryBuilder) Time(t time.Time) EntryBuilder {
e.time = t
return e
}
func (e *entryBuilder) Message(s string, args ...any) EntryBuilder {
if len(args) > 0 {
e.message = fmt.Sprintf(s, args...)
} else {
e.message = s
}
return e
}
func (e *entryBuilder) Context(ctx ...any) EntryBuilder {
e.context = append(e.context, ctx...)
return e
}
func (e *entryBuilder) Key(key string, args ...any) EntryBuilder {
e.key = key
return e
}
func (e *entryBuilder) Caller(c Caller) EntryBuilder {
e.caller = c
return e
}
func (e *entryBuilder) Level(lvl Level) EntryBuilder {
e.level = lvl
return e
}
func (e *entryBuilder) Freeze() Entry {
return EntryNode{e}
}
func (e *entryBuilder) Log(ctx context.Context) Entry {
return e.Freeze().Log(ctx)
}
func (e *entryBuilder) Notify(ctx context.Context, opts ...MessageOption) Entry {
return e.Freeze().Notify(ctx, opts...)
}