-
Notifications
You must be signed in to change notification settings - Fork 14
/
log_entry.go
78 lines (64 loc) · 1.34 KB
/
log_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
69
70
71
72
73
74
75
76
77
78
package echelon
import (
"fmt"
"time"
)
type LogLevel uint32
const (
ErrorLevel LogLevel = iota
WarnLevel
InfoLevel
DebugLevel
TraceLevel
)
type LogScopeStarted struct {
scopes []string
time time.Time
}
func NewLogScopeStarted(scopes ...string) *LogScopeStarted {
return &LogScopeStarted{
scopes: scopes,
time: time.Now(),
}
}
func (entry *LogScopeStarted) GetScopes() []string {
return entry.scopes
}
type LogScopeFinished struct {
scopes []string
finishType FinishType
}
func NewLogScopeFinished(finishType FinishType, scopes ...string) *LogScopeFinished {
return &LogScopeFinished{
scopes: scopes,
finishType: finishType,
}
}
func (entry *LogScopeFinished) FinishType() FinishType {
return entry.finishType
}
func (entry *LogScopeFinished) GetScopes() []string {
return entry.scopes
}
type LogEntryMessage struct {
Level LogLevel
scopes []string
message string
raw bool
}
func NewLogEntryMessage(scopes []string, level LogLevel, format string, arguments ...interface{}) *LogEntryMessage {
return &LogEntryMessage{
Level: level,
scopes: scopes,
message: fmt.Sprintf(format, arguments...),
}
}
func (entry *LogEntryMessage) GetMessage() string {
if entry.raw {
return entry.message
}
return entry.message + "\n"
}
func (entry *LogEntryMessage) GetScopes() []string {
return entry.scopes
}