forked from grafana/grafana
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.go
114 lines (97 loc) · 2.33 KB
/
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
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package sqlstore
import (
"fmt"
glog "github.com/grafana/grafana/pkg/log"
"github.com/go-xorm/core"
)
type XormLogger struct {
grafanaLog glog.Logger
level glog.Lvl
showSQL bool
}
func NewXormLogger(level glog.Lvl, grafanaLog glog.Logger) *XormLogger {
return &XormLogger{
grafanaLog: grafanaLog,
level: level,
showSQL: true,
}
}
// Error implement core.ILogger
func (s *XormLogger) Error(v ...interface{}) {
if s.level <= glog.LvlError {
s.grafanaLog.Error(fmt.Sprint(v...))
}
}
// Errorf implement core.ILogger
func (s *XormLogger) Errorf(format string, v ...interface{}) {
if s.level <= glog.LvlError {
s.grafanaLog.Error(fmt.Sprintf(format, v...))
}
}
// Debug implement core.ILogger
func (s *XormLogger) Debug(v ...interface{}) {
if s.level <= glog.LvlDebug {
s.grafanaLog.Debug(fmt.Sprint(v...))
}
}
// Debugf implement core.ILogger
func (s *XormLogger) Debugf(format string, v ...interface{}) {
if s.level <= glog.LvlDebug {
s.grafanaLog.Debug(fmt.Sprintf(format, v...))
}
}
// Info implement core.ILogger
func (s *XormLogger) Info(v ...interface{}) {
if s.level <= glog.LvlInfo {
s.grafanaLog.Info(fmt.Sprint(v...))
}
}
// Infof implement core.ILogger
func (s *XormLogger) Infof(format string, v ...interface{}) {
if s.level <= glog.LvlInfo {
s.grafanaLog.Info(fmt.Sprintf(format, v...))
}
}
// Warn implement core.ILogger
func (s *XormLogger) Warn(v ...interface{}) {
if s.level <= glog.LvlWarn {
s.grafanaLog.Warn(fmt.Sprint(v...))
}
}
// Warnf implement core.ILogger
func (s *XormLogger) Warnf(format string, v ...interface{}) {
if s.level <= glog.LvlWarn {
s.grafanaLog.Warn(fmt.Sprintf(format, v...))
}
}
// Level implement core.ILogger
func (s *XormLogger) Level() core.LogLevel {
switch s.level {
case glog.LvlError:
return core.LOG_ERR
case glog.LvlWarn:
return core.LOG_WARNING
case glog.LvlInfo:
return core.LOG_INFO
case glog.LvlDebug:
return core.LOG_DEBUG
default:
return core.LOG_ERR
}
}
// SetLevel implement core.ILogger
func (s *XormLogger) SetLevel(l core.LogLevel) {
}
// ShowSQL implement core.ILogger
func (s *XormLogger) ShowSQL(show ...bool) {
s.grafanaLog.Error("ShowSQL", "show", "show")
if len(show) == 0 {
s.showSQL = true
return
}
s.showSQL = show[0]
}
// IsShowSQL implement core.ILogger
func (s *XormLogger) IsShowSQL() bool {
return s.showSQL
}