mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-24 20:23:06 +00:00
lua logger
This commit is contained in:
44
service/lualog.lua
Normal file
44
service/lualog.lua
Normal file
@@ -0,0 +1,44 @@
|
||||
local skynet = require "skynet"
|
||||
|
||||
local log_level_desc = {
|
||||
[0] = "NOLOG",
|
||||
[10] = "DEBUG",
|
||||
[20] = "INFO",
|
||||
[30] = "WARNING",
|
||||
[40] = "ERROR",
|
||||
[50] = "CRITICAL",
|
||||
[60] = "FATAL",
|
||||
}
|
||||
|
||||
--
|
||||
-- log object
|
||||
--
|
||||
function log_format(self)
|
||||
if self.tags and next(self.tags) then
|
||||
return string.format("[%s %s *%s*] [%s]%s %s", self.timestamp,self.level,self.name,table.concat(self.tags, ","),self.src,self.msg)
|
||||
else
|
||||
return string.format("[%s %s *%s*]%s %s", self.timestamp,self.level,self.name,self.src,self.msg)
|
||||
end
|
||||
end
|
||||
|
||||
--
|
||||
-- end log object
|
||||
--
|
||||
|
||||
local function log(name, modname, level, timestamp, msg, src, tags)
|
||||
print(log_format {
|
||||
name = name,
|
||||
modname = modname,
|
||||
level = log_level_desc[level],
|
||||
timestamp = timestamp,
|
||||
msg = msg,
|
||||
src = src or '',
|
||||
tags = tags,
|
||||
})
|
||||
end
|
||||
|
||||
skynet.dispatch(function(msg, sz , session , from)
|
||||
log(skynet.unpack(msg,sz))
|
||||
end)
|
||||
|
||||
skynet.register ".lualog"
|
||||
Reference in New Issue
Block a user