diff --git a/src/rest/response.lua b/src/rest/response.lua index e1588f0..e740341 100644 --- a/src/rest/response.lua +++ b/src/rest/response.lua @@ -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 diff --git a/src/script/loglite.lua b/src/script/loglite.lua index 4e88d9b..52ff68d 100644 --- a/src/script/loglite.lua +++ b/src/script/loglite.lua @@ -54,7 +54,8 @@ local DEFAULT_FILTERSET = { ['patterns'] = { ['%(error%)'] = 'red', ['%(warning%)'] = 'yellow', - ['%(bulk%)'] = 'gray' + ['%(bulk%)'] = 'gray', + ['setState%(%)'] = 'bblue' } } diff --git a/src/util/logger.lua b/src/util/logger.lua index 3ce3af4..5ce3d1a 100644 --- a/src/util/logger.lua +++ b/src/util/logger.lua @@ -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