-
Notifications
You must be signed in to change notification settings - Fork 14
/
mysql.go
62 lines (46 loc) · 1.29 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
package apilogger
import (
"reflect"
"time"
"github.com/latolukasz/beeorm"
)
type mysqlDBLog struct {
logEntity ILogEntity
currentLog ILogEntity
}
func NewMysqlAPILogger(entity ILogEntity) IAPILogger {
return &mysqlDBLog{logEntity: entity}
}
func (l *mysqlDBLog) LogStart(ormService *beeorm.Engine, logType string, request interface{}) {
var logEntity ILogEntity
if l.logEntity.GetID() == 0 {
logEntity = l.logEntity
} else {
logEntity = reflect.New(reflect.ValueOf(l.logEntity).Elem().Type()).Interface().(ILogEntity)
}
logEntity.SetType(logType)
logEntity.SetRequest(request)
logEntity.SetStatus("new")
logEntity.SetCreatedAt(time.Now())
ormService.Flush(logEntity)
l.currentLog = logEntity
}
func (l *mysqlDBLog) LogError(ormService *beeorm.Engine, message string, response interface{}) {
if l.currentLog == nil {
panic("log is not created")
}
currentLog := l.currentLog
currentLog.SetMessage(message)
currentLog.SetResponse(response)
currentLog.SetStatus("failed")
ormService.Flush(currentLog)
}
func (l *mysqlDBLog) LogSuccess(ormService *beeorm.Engine, response interface{}) {
if l.currentLog == nil {
panic("log is not created")
}
currentLog := l.currentLog
currentLog.SetStatus("completed")
currentLog.SetResponse(response)
ormService.Flush(currentLog)
}