serverLogUtil.lua 5.0 KB

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