summaryrefslogtreecommitdiff
path: root/server-beta/src/brave/log.lua
diff options
context:
space:
mode:
Diffstat (limited to 'server-beta/src/brave/log.lua')
-rw-r--r--server-beta/src/brave/log.lua50
1 files changed, 50 insertions, 0 deletions
diff --git a/server-beta/src/brave/log.lua b/server-beta/src/brave/log.lua
new file mode 100644
index 00000000..d86be162
--- /dev/null
+++ b/server-beta/src/brave/log.lua
@@ -0,0 +1,50 @@
+local brave = require 'brave'
+
+local tablePack = table.pack
+local tostring = tostring
+local tableConcat = table.concat
+local debugTraceBack = debug.traceback
+local debugGetInfo = debug.getinfo
+
+_ENV = nil
+
+local function pushLog(level, ...)
+ local t = tablePack(...)
+ for i = 1, t.n do
+ t[i] = tostring(t[i])
+ end
+ local str = tableConcat(t, '\t', 1, t.n)
+ if level == 'error' then
+ str = str .. '\n' .. debugTraceBack(nil, 3)
+ end
+ local info = debugGetInfo(3, 'Sl')
+ brave.push('log', {
+ msg = str,
+ info = info,
+ })
+ return str
+end
+
+local m = {}
+
+function m.info(...)
+ pushLog('info', ...)
+end
+
+function m.debug(...)
+ pushLog('debug', ...)
+end
+
+function m.trace(...)
+ pushLog('trace', ...)
+end
+
+function m.warn(...)
+ pushLog('warn', ...)
+end
+
+function m.error(...)
+ pushLog('error', ...)
+end
+
+return m