Priority level internal handling

Handle internally as ints, then translate as appropriate in outputs
This commit is contained in:
Henri DF
2016-03-30 14:38:18 -07:00
parent d6dee28bbe
commit c9806407e8
2 changed files with 8 additions and 3 deletions

View File

@@ -160,7 +160,7 @@ local function normalize_level(level)
level = string.lower(level)
for i,v in ipairs(valid_levels) do
if (string.find(v, "^"..level)) then
return v
return i - 1 -- (syslog levels start at 0, lua indices start at 1)
end
end
error("Invalid severity level: "..level)

View File

@@ -1,17 +1,22 @@
local mod = {}
levels = {"Emergency", "Alert", "Critical", "Error", "Warning", "Notice", "Informational", "Debug"}
function mod.stdout(evt, level, format)
format = "%evt.time: "..level.." "..format
format = "%evt.time: "..levels[level+1].." "..format
formatter = digwatch.formatter(format)
msg = digwatch.format_event(evt, formatter)
print (msg)
end
function mod.syslog(evt, level, format)
-- https://neopallium.github.io/nixio/modules/nixio.html#nixio.syslog
levels = {"emerg", "alert", "crit", "err", "warning", "notice", "info", "debug"}
nixio = require("nixio")
formatter = digwatch.formatter(format)
msg = digwatch.format_event(evt, formatter)
nixio.syslog(level, msg)
nixio.syslog(levels[level+1], msg)
end
return mod