From c9806407e8fb9f0f683fb73238b31efc62cc7e06 Mon Sep 17 00:00:00 2001 From: Henri DF Date: Wed, 30 Mar 2016 14:38:18 -0700 Subject: [PATCH] Priority level internal handling Handle internally as ints, then translate as appropriate in outputs --- userspace/digwatch/lua/compiler.lua | 2 +- userspace/digwatch/lua/output.lua | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/userspace/digwatch/lua/compiler.lua b/userspace/digwatch/lua/compiler.lua index 9a414085..2df747d7 100644 --- a/userspace/digwatch/lua/compiler.lua +++ b/userspace/digwatch/lua/compiler.lua @@ -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) diff --git a/userspace/digwatch/lua/output.lua b/userspace/digwatch/lua/output.lua index f344a5ef..26a39ac0 100644 --- a/userspace/digwatch/lua/output.lua +++ b/userspace/digwatch/lua/output.lua @@ -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