/
hclog.go
95 lines (73 loc) · 2.16 KB
/
hclog.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package log
import (
"fmt"
"github.com/hashicorp/go-hclog"
)
func DefaultHCLogger() Logger {
logger := hclog.New(&hclog.LoggerOptions{
Level: hclog.DefaultLevel,
JSONFormat: true,
})
return &hcLogger{logger}
}
// hcLogger implements log.Logger interface. The underlying implementation is
// based on hashicorp/go-hclog logger
type hcLogger struct {
hclog.Logger
}
func (l *hcLogger) Debug(args ...interface{}) {
l.Logger.Debug(fmt.Sprint(args...))
}
func (l *hcLogger) Info(args ...interface{}) {
l.Logger.Info(fmt.Sprint(args...))
}
func (l *hcLogger) Warn(args ...interface{}) {
l.Logger.Warn(fmt.Sprint(args...))
}
func (l *hcLogger) Error(args ...interface{}) {
l.Logger.Error(fmt.Sprint(args...))
}
func (l *hcLogger) Panic(args ...interface{}) {
msg := fmt.Sprint(args...)
l.Logger.Error(msg)
panic(msg)
}
func (l *hcLogger) Debugw(msg string, keysAndValues ...interface{}) {
l.Logger.Debug(msg, keysAndValues...)
}
func (l *hcLogger) Infow(msg string, keysAndValues ...interface{}) {
l.Logger.Info(msg, keysAndValues...)
}
func (l *hcLogger) Warnw(msg string, keysAndValues ...interface{}) {
l.Logger.Warn(msg, keysAndValues...)
}
func (l *hcLogger) Errorw(msg string, keysAndValues ...interface{}) {
l.Logger.Error(msg, keysAndValues...)
}
func (l *hcLogger) Panicw(msg string, keysAndValues ...interface{}) {
l.Logger.Error(msg, keysAndValues...)
panic(msg)
}
func (l *hcLogger) Debugf(template string, args ...interface{}) {
l.Logger.Debug(fmt.Sprintf(template, args...))
}
func (l *hcLogger) Infof(template string, args ...interface{}) {
l.Logger.Info(fmt.Sprintf(template, args...))
}
func (l *hcLogger) Warnf(template string, args ...interface{}) {
l.Logger.Warn(fmt.Sprintf(template, args...))
}
func (l *hcLogger) Errorf(template string, args ...interface{}) {
l.Logger.Error(fmt.Sprintf(template, args...))
}
func (l *hcLogger) Panicf(template string, args ...interface{}) {
msg := fmt.Sprintf(template, args...)
l.Logger.Error(msg)
panic(msg)
}
func (l *hcLogger) With(args ...interface{}) Logger {
return &hcLogger{l.Logger.With(args...)}
}
func (l *hcLogger) SetLevel(lvl string) {
l.Logger.SetLevel(hclog.LevelFromString(lvl))
}