-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathspoor.go
54 lines (46 loc) · 859 Bytes
/
spoor.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
package spoor
import (
"io"
"log"
)
type Spoor struct {
Logger
cfgLevel Level
prefix string
flag int
}
type Option func(spoor *Spoor)
func WithFileWriter(writer *FileWriter) Option {
return func(spoor *Spoor) {
writer.level = spoor.cfgLevel
spoor.SetOutput(writer)
}
}
func WithConsoleWriter(writer io.Writer) Option {
return func(spoor *Spoor) {
spoor.SetOutput(writer)
}
}
func NewSpoor(cfgLevel Level, prefix string, flag int, opts ...Option) *Spoor {
logger := log.New(io.Discard, prefix, flag)
s := &Spoor{
Logger: logger,
cfgLevel: cfgLevel,
}
for _, opt := range opts {
opt(s)
}
return s
}
func (l *Spoor) CheckLevel(level Level) bool {
if level >= l.cfgLevel {
return false
}
return true
}
type LoggingSetting struct {
Dir string
Level int
Prefix string
WriterOption Option
}