/
structured_logger.go
70 lines (55 loc) · 1.25 KB
/
structured_logger.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
package logger
import (
"go.uber.org/zap"
)
type StructuredLog struct {
*zap.Logger
level Level
}
//type Field interface {
// String(key string, val string) Field
// Error(err error) Field
// Any(key string, val interface{}) Field
//}
//
//var LogField = StructuredLogField{}
//
//type StructuredLogField struct {
// zap.Field
//}
type Field struct {
zap.Field
}
func (l *StructuredLog) DebugString(key string, val string) zap.Field {
if l.level >= DebugLevel {
return zap.String(key, val)
}
return zap.Skip()
}
func (l *StructuredLog) String(key string, val string) zap.Field {
return zap.String(key, val)
}
func (l *StructuredLog) DebugAny(key string, val interface{}) zap.Field {
if l.level >= DebugLevel {
return zap.Any(key, val)
}
return zap.Skip()
}
func (l *StructuredLog) Any(key string, val interface{}) zap.Field {
return zap.Any(key, val)
}
//func (s StructuredLogField) Error(err error) Field {
// panic("implement me")
//}
//
//func (s StructuredLogField) Any(key string, val interface{}) Field {
// panic("implement me")
//}
func NewStructuredLog(level Level) StructuredLog {
if level >= DebugLevel {
l, _ := zap.NewDevelopment()
return StructuredLog{l, level}
}
l, _ := zap.NewProduction()
return StructuredLog{l, level}
}