/
byolog.go
49 lines (38 loc) · 979 Bytes
/
byolog.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
package byolog
// Field represents a field for structured logging.
type Field struct {
Name string
Value interface{}
}
// NewField creates a new field.
func NewField(name string, value interface{}) Field {
return Field{Name: name, Value: value}
}
// Logger represents any structured logger.
type Logger interface {
Error(msg string, fields ...Field)
Warn(msg string, fields ...Field)
Info(msg string, fields ...Field)
Debug(msg string, fields ...Field)
With(fields ...Field) Logger
Named(name string) Logger
}
type nop struct{}
// Nop creates a logger which satisfies the interface and does nothing.
func Nop() Logger {
return &nop{}
}
func (n *nop) Error(msg string, fields ...Field) {
}
func (n *nop) Warn(msg string, fields ...Field) {
}
func (n *nop) Info(msg string, fields ...Field) {
}
func (n *nop) Debug(msg string, fields ...Field) {
}
func (n *nop) With(fields ...Field) Logger {
return n
}
func (n *nop) Named(name string) Logger {
return n
}