From 469dbd257f1a250d8883bf0adbbb5786e12258b3 Mon Sep 17 00:00:00 2001 From: Jordan Irwin Date: Wed, 7 Jul 2021 18:48:38 -0700 Subject: [PATCH] Cleanup logging --- init.lua | 23 +++++++++++++++++++++++ logging.lua | 15 ++++++--------- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/init.lua b/init.lua index 108c2ff..d82ca73 100644 --- a/init.lua +++ b/init.lua @@ -14,6 +14,29 @@ listitems = {} listitems.modname = core.get_current_modname() listitems.modpath = core.get_modpath(listitems.modname) +function listitems.log(lvl, msg) + if not msg then + msg = lvl + lvl = nil + end + + local prefix = "[" .. listitems.modname .. "]" + if lvl == "debug" then + if not listitems.debug then return end + + prefix = prefix .. "[DEBUG]" + end + + msg = prefix .. " " .. msg + + if not lvl then + core.log(msg) + else + core.log(lvl, msg) + end +end + + local scripts = { "settings", "logging", diff --git a/logging.lua b/logging.lua index c25d456..6aa77c0 100644 --- a/logging.lua +++ b/logging.lua @@ -11,31 +11,28 @@ -- LOGGING FUNCTIONS -- Custom logging function -function listitems.log(level, msg) - local prefix = "[" .. listitems.modname .. "] " - - if msg == nil then - core.log(prefix .. level) - else - core.log(level, prefix .. msg) - end -end -- Custom "info" level logging function function listitems.logInfo(msg) + listitems.log("warning", "\"listitems.logInfo\" is deprecated, use \"listitems.log\"") + listitems.log("info", msg) end -- Custom "warning" level logging function function listitems.logWarn(msg) + listitems.log("warning", "\"listitems.logWarn\" is deprecated, use \"listitems.log\"") + listitems.log("warning", msg) end -- Custom debug logging function function listitems.logDebug(msg) + listitems.log("warning", "\"listitems.logDebug\" is deprecated, use \"listitems.log\"") + if listitems.debug then core.log("[DEBUG: " .. listitems.modname .. "] " .. msg) end