-
Notifications
You must be signed in to change notification settings - Fork 14
/
log_entry.go
76 lines (62 loc) · 1.28 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
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
success bool
}
func NewLogScopeFinished(success bool, scopes ...string) *LogScopeFinished {
return &LogScopeFinished{
scopes: scopes,
success: success,
}
}
func (entry *LogScopeFinished) Success() bool {
return entry.success
}
func (entry *LogScopeFinished) GetScopes() []string {
return entry.scopes
}
type LogEntryMessage struct {
Level LogLevel
format string
arguments []interface{}
scopes []string
}
func NewLogEntryMessage(scopes []string, level LogLevel, format string, a ...interface{}) *LogEntryMessage {
return &LogEntryMessage{
Level: level,
format: format,
arguments: a,
scopes: scopes,
}
}
func (entry *LogEntryMessage) GetMessage() string {
return fmt.Sprintf(entry.format, entry.arguments...)
}
func (entry *LogEntryMessage) GetScopes() []string {
return entry.scopes
}