Blame view

src/models/RoleLog.lua 1.09 KB
4c5d72ab   zhouhaihai   高级pvp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
  
  
  -- logType  日志 mapping 信息(确定后不能更改类型) 修改需要设置 es 日志mapping
  
  
  
  local LogType = {
  	create = {
  		ip = "string"
  	},
  	login = {
  		ip = "string"
  	},
  	logout = {
  		online = "number"
  	},
  
  }
  
  
  -- 所有的日志都包括的部分 role 里面的信息
  local commonField = {
  	name = "string",
  	id = "number",
  	uid = "string",
  	sId = "number",
  	device = "string",
  	ctime = "number",
  	ltime = "number",
  	level = "number",
  	rmbC = "number",
  }
  
  local RoleLog = {}
  
  function RoleLog.bind(Role)
  
  	function Role:log(logType, contents)
  
  		local _logType = LogType[logType]
  		if not _logType then return end
  
  
  		if not logd then return end
  
  		contents = contents or {}
  		local doc = {}
  		for field, _typ in pairs(commonField) do
  			doc[field] = self:getProperty(field)
  		end
  		for field, value in pairs(contents) do
  			if _logType[field] then
  				doc[field] = value
  			else
  				print(string.format("LOG ERROR:  %s  had new field  %s  no type.", logType, field))
  			end
  		end
  		
  		doc.mid = doc.uid:sub(-2, -1)
  		pcall(skynet.send, logd, "lua", "log", logType, doc)
  	end
  
  end
  
  return RoleLog