diff options
| author | Alexander Pickering <alexandermpickering@gmail.com> | 2019-05-04 16:07:24 -0400 |
|---|---|---|
| committer | Alexander Pickering <alexandermpickering@gmail.com> | 2019-05-04 16:07:24 -0400 |
| commit | aacf5fbcfe1e6f2cdb0c6ab19b3e8dd87e3fd488 (patch) | |
| tree | 2ebd6714643d8cfdd07a2d6130d369d79ab9bbbd /gamemode/shared/log.lua | |
| parent | 446dcbfdbd4166505518262f7c8c233a3005aea5 (diff) | |
| download | artery-aacf5fbcfe1e6f2cdb0c6ab19b3e8dd87e3fd488.tar.gz artery-aacf5fbcfe1e6f2cdb0c6ab19b3e8dd87e3fd488.tar.bz2 artery-aacf5fbcfe1e6f2cdb0c6ab19b3e8dd87e3fd488.zip | |
Refactored logging utility
refactored logging so that everything is much cleaner.
Diffstat (limited to 'gamemode/shared/log.lua')
| -rw-r--r-- | gamemode/shared/log.lua | 62 |
1 files changed, 40 insertions, 22 deletions
diff --git a/gamemode/shared/log.lua b/gamemode/shared/log.lua index 8005000..5fc043f 100644 --- a/gamemode/shared/log.lua +++ b/gamemode/shared/log.lua @@ -13,30 +13,48 @@ elseif CLIENT then domain = "[CLIENT]" end ---- Print a debug message. --- This can be suppressed in release versions -function log.debug(...) - MsgC(col.console.gray,domain,"[DEBUG]",table.concat({...}," "),"\n") +local log_levels = { + debug = { + color = col.console.gray,domain, + prefix = "[DEBUG]" + }, + info = { + color = col.console.cyan,domain, + prefix = "[INFO]", + }, + warn = { + color = col.console.yellow,domain, + prefix = "[WARNING]", + }, + error = { + color = col.console.red,domain, + prefix = "[ERROR]", + }, +} +local level = "debug" +local rev_levels = {} +local rev_level_counter = 1 +for k,v in pairs(log_levels) do + rev_levels[k] = rev_level_counter + rev_level_counter = rev_level_counter + 1 end ---- Print an information message. --- Things server owners might want to see -function log.info(...) - MsgC(col.console.cyan,domain,"[INFO]",table.concat({...}," "),"\n") -end - ---- Prints a warning. --- Things developers need to look at --- Maybe print this to a file in the future? -function log.warn(...) - MsgC(col.console.yellow,domain,"[WARNING]",table.concat({...}," "),"\n") -end - ---- Prints an error. --- Things that should never happen --- Maybe have this automatically make bugs on the bug tracker with the above log files? -function log.error(...) - MsgC(col.console.red,domain,"[ERROR]",table.concat({...}," "),"\n") +for mode,settings in pairs(log_levels) do + log[mode] = function(...) + if rev_levels[mode] >= rev_levels[level] then + local args = {...} + local toprint = {domain, settings.prefix} + for _,part in pairs(args) do + toprint[#toprint + 1] = tostring(part) + end + toprint[#toprint + 1] = "\n" + MsgC(settings.color,table.concat(toprint," ")) + end + end + log[mode .. "f"] = function(...) + local args = {...} + log[mode](string.format(unpack(args))) + end end log.report = fn.curry( |
