serverLogUtil.lua 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. -- 服务端埋点日志工具文件
  2. local skynet = require "skynet"
  3. local timeUtil = require "utils.timeUtil"
  4. local lib_game_redis = require("lib_game_redis")
  5. local root = {}
  6. local function writeServerLog(key, date, data)
  7. assert(key and date)
  8. local file = string.format("%s-%s", key, date)
  9. skynet.send("statisticLog", "lua", "add_file_log", file, data)
  10. end
  11. function root.getActiveKey(date)
  12. return "active:uid:" .. date
  13. end
  14. function root.formatData(data)
  15. return table.concat(data, ";")
  16. end
  17. function root.formatContent(data)
  18. return table.concat(data, ",")
  19. end
  20. -- 新增活跃天玩家
  21. local function l_add_active_user(uid)
  22. local currTime = timeUtil.currentTime()
  23. local date = timeUtil.toDate(currTime)
  24. local key = root.getActiveKey(date)
  25. -- log.info("l_add_active_user key[%s] uid[%s]", tostring(key), tostring(uid))
  26. lib_game_redis:sadd(key, uid)
  27. end
  28. -- 服务端事件埋点
  29. function root.logEvent(uid, version, channel, eventId, extraParams)
  30. local now = timeUtil.currentTime()
  31. local date = timeUtil.toDate(now)
  32. local dateStr = timeUtil.toString(now)
  33. local data = {
  34. date,
  35. dateStr,
  36. uid or "",
  37. version or "",
  38. channel or "",
  39. eventId or "",
  40. extraParams or ""
  41. }
  42. local dataStr = root.formatData(data)
  43. writeServerLog("event", date, dataStr)
  44. end
  45. -- 服务端资源埋点
  46. function root.logResource(uid, eventId, itemId, resChgs, resResult, channel, bandShareCode)
  47. local now = timeUtil.currentTime()
  48. local date = timeUtil.toDate(now)
  49. local dateStr = timeUtil.toString(now)
  50. local data = {
  51. date,
  52. dateStr,
  53. uid,
  54. bandShareCode,
  55. channel,
  56. eventId,
  57. itemId,
  58. resChgs or 0,
  59. resResult or 0
  60. }
  61. local dataStr = root.formatData(data)
  62. writeServerLog("resource", date, dataStr)
  63. end
  64. -- 服务端注册埋点
  65. function root.logRegister(uid, channel, version, machineType, uuid, udid, ip, userType)
  66. local now = timeUtil.currentTime()
  67. local date = timeUtil.toDate(now)
  68. local dateStr = timeUtil.toString(now)
  69. local data = {
  70. date,
  71. uid or "",
  72. dateStr,
  73. channel or "",
  74. version or "",
  75. machineType or "",
  76. uuid or "",
  77. udid or "",
  78. ip or "",
  79. userType or ""
  80. }
  81. local dataStr = root.formatData(data)
  82. -- 添加到每日活跃信息中
  83. l_add_active_user(uid)
  84. writeServerLog("register", date, dataStr)
  85. end
  86. -- 服务端登录埋点
  87. function root.logLogin(uid, channel, version, machineType, operator, network, uuid, udid, ip, userType)
  88. local now = timeUtil.currentTime()
  89. local date = timeUtil.toDate(now)
  90. local dateStr = timeUtil.toString(now)
  91. local data = {
  92. date,
  93. uid or 0,
  94. channel or "",
  95. version or "",
  96. dateStr,
  97. machineType or "",
  98. operator or "",
  99. network or "",
  100. uuid or "",
  101. udid or "",
  102. ip or "",
  103. userType or ""
  104. }
  105. local dataStr = root.formatData(data)
  106. -- 添加到每日活跃信息中
  107. l_add_active_user(uid)
  108. writeServerLog("login", date, dataStr)
  109. end
  110. -- 服务端登出埋点
  111. function root.logLogout(uid, channel, runTimes, version, battleCount, items, isFinishGuide, guideStep)
  112. local now = timeUtil.currentTime()
  113. local date = timeUtil.toDate(now)
  114. local dateStr = timeUtil.toString(now)
  115. local data = {
  116. date,
  117. dateStr,
  118. uid or "",
  119. channel or "",
  120. runTimes or "",
  121. version or ""
  122. }
  123. local dataStr = root.formatData(data)
  124. -- 添加到每日活跃信息中
  125. l_add_active_user(uid)
  126. writeServerLog("logout", date, dataStr)
  127. end
  128. -- 服务端支付埋点
  129. function root.logPay(playerInfo, orderInfo)
  130. if is_empty(playerInfo) or is_empty(orderInfo) then
  131. return
  132. end
  133. local now = timeUtil.currentTime()
  134. local date = timeUtil.toDate(now)
  135. local dateStr = timeUtil.toString(now)
  136. local data = {
  137. date,
  138. dateStr,
  139. playerInfo.uid or "",
  140. playerInfo.bandShareCode or "",
  141. playerInfo.version or "",
  142. orderInfo.orderNo or "",
  143. orderInfo.pay or "",
  144. orderInfo.itemId or "",
  145. orderInfo.amount or "",
  146. orderInfo.status or "",
  147. orderInfo.retmsg or ""
  148. }
  149. local dataStr = root.formatData(data)
  150. writeServerLog("pay", date, dataStr)
  151. end
  152. return root