-
Notifications
You must be signed in to change notification settings - Fork 2
/
transport.go
66 lines (52 loc) · 1.15 KB
/
transport.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
package lightlog
// ITransport Define an interface called ITransport with several methods
type ITransport interface {
Enable()
Disable()
ShouldLog(level Level) bool
Log(data *LogData)
Flush()
FlushSync()
Reload()
Close()
}
type Transport struct {
name string // The name of the transport
level Level // The level of the transport
enabled bool // The enabled state of the transport
}
// NewTransport Create a new Transport object
func NewTransport(name string, level Level) *Transport {
return &Transport{
name: name,
level: level,
enabled: true,
}
}
// Enable the transport
func (t *Transport) Enable() {
t.enabled = true
}
// Disable the transport
func (t *Transport) Disable() {
t.enabled = false
}
// ShouldLog Check if the transport should log a message with the given level
func (t *Transport) ShouldLog(level Level) bool {
if !t.enabled {
return false
}
return level >= t.level
}
// Flush log data
func (t *Transport) Flush() {
}
// FlushSync flush log data synchronously
func (t *Transport) FlushSync() {
}
// Reload the transport
func (t *Transport) Reload() {
}
// Close the transport
func (t *Transport) Close() {
}