-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper_functions.lua
41 lines (37 loc) · 1.07 KB
/
helper_functions.lua
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
--- Logs a message with optional traceback.
--
-- @local log_message
-- @tparam string level
-- Log verbosity level.
-- @tparam string message.
-- Text to be logged.
-- @tparam[opt] traceback
-- Toggles printing traceback (default: `false`).
local function log_message(level, message, traceback)
if traceback then
core.log(level, message .. "\n" .. debug.traceback())
else
core.log(level, mesage)
end
end
--- Logs an error message with optional traceback.
--
-- @local log_error
-- @tparam string message
-- Message to be logged.
-- @tparam[opt] boolean traceback
-- Toggles printing traceback (default: `true`).
local function log_error(message, traceback)
log_message("error", message, traceback or traceback == nil)
end
--- Logs a warning message with optional traceback.
--
-- @local log_error
-- @tparam string message
-- Message to be logged.
-- @tparam[opt] boolean traceback
-- Toggles printing traceback (default: `false`).
local function log_warn(message, traceback)
log_message("warning", message, traceback)
end
return log_error, log_warn