-
Notifications
You must be signed in to change notification settings - Fork 0
/
unbuffered.go
72 lines (58 loc) · 1.58 KB
/
unbuffered.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
package frog
import (
"fmt"
"io"
)
type Unbuffered struct {
writer io.Writer
prn Printer
minLevel Level
}
func NewUnbuffered(writer io.Writer, prn Printer) *Unbuffered {
return &Unbuffered{
writer: writer,
prn: prn,
minLevel: Info,
}
}
func (l *Unbuffered) Close() {
// this space intentionally left blank (nothing to cleanup or flush)
}
func (l *Unbuffered) MinLevel() Level {
return l.minLevel
}
func (l *Unbuffered) SetMinLevel(level Level) Logger {
l.minLevel = level
return l
}
func (l *Unbuffered) LogImpl(level Level, msg string, fielders []Fielder, opts []PrinterOption, d ImplData) {
d.MergeMinLevel(l.minLevel)
if level < d.MinLevel {
return
}
fmt.Fprintf(l.writer, "%s\n", l.prn.Render(level, opts, msg, FieldifyAndAppend(d.Fields, fielders)))
}
func (l *Unbuffered) Transient(msg string, fielders ...Fielder) Logger {
l.LogImpl(Transient, msg, fielders, nil, ImplData{})
return l
}
func (l *Unbuffered) Verbose(msg string, fielders ...Fielder) Logger {
l.LogImpl(Verbose, msg, fielders, nil, ImplData{})
return l
}
func (l *Unbuffered) Info(msg string, fielders ...Fielder) Logger {
l.LogImpl(Info, msg, fielders, nil, ImplData{})
return l
}
func (l *Unbuffered) Warning(msg string, fielders ...Fielder) Logger {
l.LogImpl(Warning, msg, fielders, nil, ImplData{})
return l
}
func (l *Unbuffered) Error(msg string, fielders ...Fielder) Logger {
l.LogImpl(Error, msg, fielders, nil, ImplData{})
return l
}
func (l *Unbuffered) Log(level Level, msg string, fielders ...Fielder) Logger {
l.LogImpl(level, msg, fielders, nil, ImplData{})
return l
}