1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
--- Logging utility.
-- This prints things to the console for now, maybe it can automatically file bugs and save bug reports in the future?
--@shared log.lua
local log = {}
local fn = nrequire("fn.lua")
local col = nrequire("colortheme.lua")
local domain
if SERVER then
domain = "[SERVER]"
elseif CLIENT then
domain = "[CLIENT]"
end
local log_levels = {
--- Debugging messages.
-- Prints out messages for debugging, each parameter will have `tostring()`
-- called on it, interleaved with spaces and with `[DEBUG]` prepended to the whole string.
--@function debug(...)
--@param ... values to print
debug = {
color = col.console.gray,domain,
prefix = "[DEBUG]"
},
--- Informational messages.
-- Prints out messages, each parameter will have `tostring()`
-- called on it, interleaved with spaces and with `[INFO]` prepended to the whole string.
--@function info(...)
--@param ... values that will have `tostring()` called on them, prefixed with `[INFO]` and interleaved with spaces.
info = {
color = col.console.cyan,domain,
prefix = "[INFO]",
},
--- Warning messages.
-- Prints out warning messages, each parameter will have `tostring()`
-- called on it, interleaved with spaces and with `[WARN]` prepended to the whole string.
--@function warn(...)
--@param ... values that will have `tostring()` called on them, prefixed with `[WARN]` and interleaved with spaces.
warn = {
color = col.console.yellow,domain,
prefix = "[WARNING]",
},
--- Error messages.
-- Prints out warning messages, each parameter will have `tostring()`
-- called on it, interleaved with spaces and with `[ERROR]` prepended to the whole string.
--@function error(...)
--@param ... values that will have `tostring()` called on them, prefixed with `[ERROR]` and interleaved with spaces.
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
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(
file.Append,
"artery/report_log.txt"
)
return log
|