game_sync/gamesrv/base/logchannel.go

62 lines
1.7 KiB
Go

package base
import (
"reflect"
"mongo.games.com/goserver/core/logger"
"mongo.games.com/game/model"
"mongo.games.com/game/mq"
)
// LogChannelSingleton 日志记录器
var LogChannelSingleton = &LogChannel{
cName: make(map[reflect.Type]string),
}
type LogChannel struct {
cName map[reflect.Type]string
}
func (c *LogChannel) RegisterLogCName(cname string, log interface{}) {
t := c.getLogType(log)
c.cName[t] = cname
}
func (c *LogChannel) getLogType(log interface{}) reflect.Type {
return reflect.Indirect(reflect.ValueOf(log)).Type()
}
func (c *LogChannel) getLogCName(log interface{}) string {
t := c.getLogType(log)
if name, exist := c.cName[t]; exist {
return name
}
return ""
}
func (c *LogChannel) WriteLog(log interface{}) {
cname := c.getLogCName(log)
if cname == "" {
cname = "_null_"
}
logger.Logger.Tracef("LogChannel ==> %#v", log)
mq.Send(cname, log)
}
func (c *LogChannel) WriteMQData(data *model.RabbitMQData) {
mq.Send(data.MQName, data.Data)
}
func init() {
LogChannelSingleton.RegisterLogCName(model.LoginLogCollName, &model.LoginLog{})
LogChannelSingleton.RegisterLogCName(model.CoinGiveLogCollName, &model.CoinGiveLog{})
LogChannelSingleton.RegisterLogCName(model.CoinLogCollName, &model.CoinLog{})
LogChannelSingleton.RegisterLogCName(model.SceneCoinLogCollName, &model.SceneCoinLog{})
LogChannelSingleton.RegisterLogCName(model.GameDetailedLogCollName, &model.GameDetailedLog{})
LogChannelSingleton.RegisterLogCName(model.GamePlayerListLogCollName, &model.GamePlayerListLog{})
LogChannelSingleton.RegisterLogCName(model.FriendRecordLogCollName, &model.FriendRecord{})
LogChannelSingleton.RegisterLogCName(model.ItemLogCollName, &model.ItemLog{})
LogChannelSingleton.RegisterLogCName(mq.DBCustomLog, &model.CustomLog{})
}