123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- -- 服务端埋点日志工具文件
- local skynet = require "skynet"
- local timeUtil = require "utils.timeUtil"
- local lib_game_redis = require("lib_game_redis")
- local root = {}
- local function writeServerLog(key, date, data)
- assert(key and date)
- local file = string.format("%s-%s", key, date)
- skynet.send("statisticLog", "lua", "add_file_log", file, data)
- end
- function root.getActiveKey(date)
- return "active:uid:" .. date
- end
- function root.formatData(data)
- return table.concat(data, ";")
- end
- function root.formatContent(data)
- return table.concat(data, ",")
- end
- -- 新增活跃天玩家
- local function l_add_active_user(uid)
- local currTime = timeUtil.currentTime()
- local date = timeUtil.toDate(currTime)
- local key = root.getActiveKey(date)
- -- log.info("l_add_active_user key[%s] uid[%s]", tostring(key), tostring(uid))
- lib_game_redis:sadd(key, uid)
- end
- -- 服务端事件埋点
- function root.logEvent(uid, version, channel, eventId, extraParams)
- local now = timeUtil.currentTime()
- local date = timeUtil.toDate(now)
- local dateStr = timeUtil.toString(now)
- local data = {
- date,
- dateStr,
- uid or "",
- version or "",
- channel or "",
- eventId or "",
- extraParams or ""
- }
- local dataStr = root.formatData(data)
- writeServerLog("event", date, dataStr)
- end
- -- 服务端资源埋点
- function root.logResource(uid, eventId, itemId, resChgs, resResult, channel, bandShareCode)
- local now = timeUtil.currentTime()
- local date = timeUtil.toDate(now)
- local dateStr = timeUtil.toString(now)
- local data = {
- date,
- dateStr,
- uid,
- bandShareCode,
- channel,
- eventId,
- itemId,
- resChgs or 0,
- resResult or 0
- }
- local dataStr = root.formatData(data)
- writeServerLog("resource", date, dataStr)
- end
- -- 服务端注册埋点
- function root.logRegister(uid, channel, version, machineType, uuid, udid, ip, userType)
- local now = timeUtil.currentTime()
- local date = timeUtil.toDate(now)
- local dateStr = timeUtil.toString(now)
- local data = {
- date,
- uid or "",
- dateStr,
- channel or "",
- version or "",
- machineType or "",
- uuid or "",
- udid or "",
- ip or "",
- userType or ""
- }
- local dataStr = root.formatData(data)
- -- 添加到每日活跃信息中
- l_add_active_user(uid)
- writeServerLog("register", date, dataStr)
- end
- -- 服务端登录埋点
- function root.logLogin(uid, channel, version, machineType, operator, network, uuid, udid, ip, userType)
- local now = timeUtil.currentTime()
- local date = timeUtil.toDate(now)
- local dateStr = timeUtil.toString(now)
- local data = {
- date,
- uid or 0,
- channel or "",
- version or "",
- dateStr,
- machineType or "",
- operator or "",
- network or "",
- uuid or "",
- udid or "",
- ip or "",
- userType or ""
- }
- local dataStr = root.formatData(data)
- -- 添加到每日活跃信息中
- l_add_active_user(uid)
- writeServerLog("login", date, dataStr)
- end
- -- 服务端登出埋点
- function root.logLogout(uid, channel, runTimes, version, battleCount, items, isFinishGuide, guideStep)
- local now = timeUtil.currentTime()
- local date = timeUtil.toDate(now)
- local dateStr = timeUtil.toString(now)
- local data = {
- date,
- dateStr,
- uid or "",
- channel or "",
- runTimes or "",
- version or ""
- }
- local dataStr = root.formatData(data)
- -- 添加到每日活跃信息中
- l_add_active_user(uid)
- writeServerLog("logout", date, dataStr)
- end
- -- 服务端支付埋点
- function root.logPay(playerInfo, orderInfo)
- if is_empty(playerInfo) or is_empty(orderInfo) then
- return
- end
- local now = timeUtil.currentTime()
- local date = timeUtil.toDate(now)
- local dateStr = timeUtil.toString(now)
- local data = {
- date,
- dateStr,
- playerInfo.uid or "",
- playerInfo.bandShareCode or "",
- playerInfo.version or "",
- orderInfo.orderNo or "",
- orderInfo.pay or "",
- orderInfo.itemId or "",
- orderInfo.amount or "",
- orderInfo.status or "",
- orderInfo.retmsg or ""
- }
- local dataStr = root.formatData(data)
- writeServerLog("pay", date, dataStr)
- end
- return root
|