-- 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