game_sync/worldsrv/logchannel.go

76 lines
2.8 KiB
Go

package main
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 ""
}
// WriteLog 记录日志,需要提前注册
func (c *LogChannel) WriteLog(log interface{}) {
cname := c.getLogCName(log)
if cname == "" {
cname = "_null_"
}
logger.Logger.Tracef("==> RabbitMQ(%v): %#v", cname, log)
mq.Send(cname, log)
}
// WriteMQData rabbitMQ消息
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.ItemLogCollName, &model.ItemLog{})
LogChannelSingleton.RegisterLogCName(model.WelfareLogCollName, &model.WelfareLog{})
LogChannelSingleton.RegisterLogCName(model.OnlineLogCollName, &model.OnlineLog{})
LogChannelSingleton.RegisterLogCName(model.MQRankSeason, &model.PlayerRankScore{})
LogChannelSingleton.RegisterLogCName(model.MQRankPlayerCoin, &model.RankPlayerCoin{})
LogChannelSingleton.RegisterLogCName(mq.BackBankrupt, &model.BankruptLog{})
LogChannelSingleton.RegisterLogCName(mq.BackReliefund, &model.ReliefFundLog{})
LogChannelSingleton.RegisterLogCName(mq.DBInvite, &model.EvtInviteMsg{})
LogChannelSingleton.RegisterLogCName(model.MQRankPlayerLevel, &model.PlayerLevelInfo{})
LogChannelSingleton.RegisterLogCName(model.MQRankPlayerPermit, &model.PermitScore{})
LogChannelSingleton.RegisterLogCName(mq.BackSystemPermitCycle, &model.BackendPermitCycle{})
LogChannelSingleton.RegisterLogCName(mq.BackSystemPermitRank, &model.BackendPermitRank{})
LogChannelSingleton.RegisterLogCName(mq.BackSystemPermitExchange, &model.BackendPermitExchange{})
LogChannelSingleton.RegisterLogCName(mq.BackSystemPermitJoin, &model.BackendPermitJoin{})
LogChannelSingleton.RegisterLogCName(mq.BackSystemPermitTask, &model.BackendPermitTask{})
LogChannelSingleton.RegisterLogCName(mq.BackClientLog, &model.ClientLogMysql{})
LogChannelSingleton.RegisterLogCName(mq.BackSystemJyb, &model.JybLog{})
LogChannelSingleton.RegisterLogCName(mq.DBVipGiftLog, &model.DbVip{})
}