-
Notifications
You must be signed in to change notification settings - Fork 0
/
DB.go
34 lines (30 loc) · 1.02 KB
/
DB.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
package log
import (
"github.com/ssgo/standard"
"github.com/ssgo/u"
)
func (logger *Logger) DB(dbType, dsn, query string, args []interface{}, usedTime float32, extra ...interface{}) {
if !logger.CheckLevel(INFO) {
return
}
logger.Log(logger.MakeDBLog(standard.LogTypeDb, dbType, dsn, query, args, usedTime, extra...))
}
func (logger *Logger) DBError(error, dbType, dsn, query string, args []interface{}, usedTime float32, extra ...interface{}) {
if !logger.CheckLevel(ERROR) {
return
}
logger.Log(standard.DBErrorLog{
DBLog: logger.MakeDBLog(standard.LogTypeDbError, dbType, dsn, query, args, usedTime, extra...),
ErrorLog: logger.MakeErrorLog(standard.LogTypeDbError, error),
})
}
func (logger *Logger) MakeDBLog(logType, dbType, dsn, query string, args []interface{}, usedTime float32, extra ...interface{}) standard.DBLog {
return standard.DBLog{
BaseLog: logger.MakeBaseLog(logType, extra...),
DbType: dbType,
Dsn: dsn,
Query: query,
QueryArgs: u.String(args),
UsedTime: usedTime,
}
}