-
Notifications
You must be signed in to change notification settings - Fork 0
/
mysql.go
94 lines (76 loc) · 1.81 KB
/
mysql.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
package log
import (
"fmt"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"xorm.io/core"
)
var coreLevelToBeegoLevel = map[core.LogLevel]zapcore.Level{
core.LOG_WARNING: zap.WarnLevel,
core.LOG_INFO: zap.InfoLevel,
core.LOG_DEBUG: zap.DebugLevel,
core.LOG_ERR: zap.ErrorLevel,
core.LOG_OFF: zap.WarnLevel,
core.LOG_UNKNOWN: zap.InfoLevel,
}
var _ core.ILogger = &MysqlLogger{}
// MysqlLogger
type MysqlLogger struct {
w *zap.Logger
showSQL bool
}
// NewMysqlLogger return a pointer to MysqlLogger
func NewMysqlLogger(w *zap.Logger) *MysqlLogger {
return &MysqlLogger{w: w}
}
// Debug ...
func (s *MysqlLogger) Debug(v ...interface{}) {
s.w.Debug(fmt.Sprint(v...))
}
// Debugf ...
func (s *MysqlLogger) Debugf(format string, v ...interface{}) {
s.w.Debug(fmt.Sprintf(format, v...))
}
// Error ...
func (s *MysqlLogger) Error(v ...interface{}) {
s.w.Error(fmt.Sprint(v...))
}
// Errorf ...
func (s *MysqlLogger) Errorf(format string, v ...interface{}) {
s.w.Error(fmt.Sprintf(format, v...))
}
// Info ...
func (s *MysqlLogger) Info(v ...interface{}) {
s.w.Info(fmt.Sprint(v...))
}
// Infof ...
func (s *MysqlLogger) Infof(format string, v ...interface{}) {
s.w.Info(fmt.Sprintf(format, v...))
}
// Warn ...
func (s *MysqlLogger) Warn(v ...interface{}) {
s.w.Warn(fmt.Sprint(v...))
}
// Warnf ...
func (s *MysqlLogger) Warnf(format string, v ...interface{}) {
s.w.Warn(fmt.Sprintf(format, v...))
}
// Level get level
func (s *MysqlLogger) Level() core.LogLevel {
return core.LOG_UNKNOWN
}
// SetLevel set level
func (s *MysqlLogger) SetLevel(l core.LogLevel) {
}
// ShowSQL show sql
func (s *MysqlLogger) ShowSQL(show ...bool) {
if len(show) == 0 {
s.showSQL = true
return
}
s.showSQL = show[0]
}
// IsShowSQL sql showed or not
func (s *MysqlLogger) IsShowSQL() bool {
return s.showSQL
}