-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.go
30 lines (23 loc) · 982 Bytes
/
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
package gormTool
import (
"context"
"fmt"
"time"
"gorm.io/gorm/logger"
)
func (w *myWriter) LogMode(logger.LogLevel) logger.Interface {
return w
}
func (w *myWriter) Info(_ context.Context, msg string, data ...interface{}) {
w.WriteString(fmt.Sprintf("%v [Info] %v\n", time.Now().Format("2006-01-02 15:04:05"), fmt.Sprintf(msg, data...)))
}
func (w *myWriter) Warn(_ context.Context, msg string, data ...interface{}) {
w.WriteString(fmt.Sprintf("%v [Warn] %v\n", time.Now().Format("2006-01-02 15:04:05"), fmt.Sprintf(msg, data...)))
}
func (w *myWriter) Error(_ context.Context, msg string, data ...interface{}) {
w.WriteString(fmt.Sprintf("%v [Error] %v\n", time.Now().Format("2006-01-02 15:04:05"), fmt.Sprintf(msg, data...)))
}
func (w *myWriter) Trace(_ context.Context, begin time.Time, fc func() (string, int64), _ error) {
sql, rows := fc()
w.WriteString(fmt.Sprintf("%v:%v [%v] | %v\n", begin.Format("2006-01-02 15:04:05"), time.Since(begin), rows, sql))
}