roleLog.go
1.28 KB
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 models
import (
"encoding/json"
"fmt"
"pro2d/common"
"pro2d/common/logger"
"pro2d/pb"
"sync/atomic"
)
var LogType = map[string]string{
"in_battle": "common",
"out_battle": "common",
"in_item": "common",
"out_item": "common",
"in_hero": "common",
"out_hero": "common",
"in_equip": "common",
"out_equip": "common",
"gm_action": "common",
"mail_action": "common",
"role_action": "common",
"hero_action": "common",
}
func (m *RoleModel) MyLog(logType string, content *pb.LogConf) {
_, ok := LogType[logType]
if !ok {
logger.Error("LOG ERROR: new logType [%s] need Add Maping.", logType)
return
}
content.Id = m.Data.Id
content.Uid = m.Data.Uid
content.Name = m.Data.Nick
content.Device = m.Data.Device
content.Level = m.Data.Level
content.Ucode = m.GetActionUnicode()
content.Typ = logType
j, err := json.Marshal(content)
if err != nil {
logger.Error("LOG ERROR: logType [%s] json.Marshal", logType)
return
}
logger.Debug(j)
}
func (m *RoleModel) StartActionUnicode() {
uniqueCount := atomic.AddInt64(&m.uniqueCount, 1)
m.actionUcode = fmt.Sprintf("%s-%d-%d", m.Data.Id, common.Timex(), uniqueCount)
}
func (m *RoleModel) EndActionUnicode() {
m.actionUcode = ""
}
func (m *RoleModel) GetActionUnicode() string {
return m.actionUcode
}