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 }