aboutsummaryrefslogtreecommitdiff
path: root/gamemode/shared
diff options
context:
space:
mode:
Diffstat (limited to 'gamemode/shared')
-rw-r--r--gamemode/shared/log.lua62
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(