Add padding to level names in log messages.

Other minor changes.
This commit is contained in:
Wouter R 2014-05-28 09:51:27 +02:00
parent 759c0a3007
commit 4f84e1060b
3 changed files with 18 additions and 5 deletions

View File

@ -170,7 +170,7 @@ function M:send()
end
if self.body.status ~= "success" then
log:verbose(MOD_ABBR, "Response: "..utils.dump(self.body.status).." ("..utils.dump(self.body.msg)..")")
log:warning(MOD_ABBR, "Response status: "..utils.dump(self.body.status).." ("..utils.dump(self.body.msg)..")")
end
end

View File

@ -54,7 +54,8 @@ local DEFAULT_FILTERSET = {
['patterns'] = {
['%(error%)'] = 'red',
['%(warning%)'] = 'yellow',
['%(bulk%)'] = 'gray'
['%(bulk%)'] = 'gray',
['setState%(%)'] = 'bblue'
}
}

View File

@ -15,6 +15,8 @@ local M = {}
local logLevel, logVerboseFmt, logStream
local LONGEST_LEVEL_NAME = -1
--- Available log levels (starting at 1)
-- @table LEVEL
M.LEVEL = {
@ -26,12 +28,19 @@ M.LEVEL = {
'bulk' -- debug information (in large amounts)
}
-- M.LEVEL already has idx=>name entries, now create name=>idx entries so it can be indexed both ways
--[[== module initialization code ==]]--
-- M.LEVEL already has idx=>name entries, now create name=>idx entries so it can be indexed both ways, and init LONGEST_LEVEL_NAME
for i,v in ipairs(M.LEVEL) do
M.LEVEL[v] = i
if v:len() > LONGEST_LEVEL_NAME then LONGEST_LEVEL_NAME = v:len() end
end
--[[================================]]--
local function log(level, module, msg, verboseFmt)
if level <= logLevel then
local now = os.date('%m-%d %H:%M:%S')
@ -43,8 +52,11 @@ local function log(level, module, msg, verboseFmt)
local m = (type(msg) == 'string') and msg or utils.dump(msg)
if module == nil then module = "LUA " end
if v then logStream:write(now .. " [" .. module .. "] (" .. M.LEVEL[level] .. "): " .. m .. " [" .. name .. "@" .. i.short_src .. ":" .. i.linedefined .. "]\n")
else logStream:write(now .. " [" .. module .. "] (" .. M.LEVEL[level] .. "): " .. m .. "\n") end
local levelName = M.LEVEL[level]
local padding = string.rep(' ', LONGEST_LEVEL_NAME - levelName:len())
if v then logStream:write(now .. " [" .. module .. "] (" .. levelName .. ")" .. padding .. ": " .. m .. " [" .. name .. "@" .. i.short_src .. ":" .. i.linedefined .. "]\n")
else logStream:write(now .. " [" .. module .. "] (" .. levelName .. ")" .. padding .. ": " .. m .. "\n") end
logStream:flush()
end