summaryrefslogtreecommitdiff
path: root/script/brave/log.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2020-11-20 21:57:09 +0800
committer最萌小汐 <sumneko@hotmail.com>2020-11-20 21:57:09 +0800
commit4ca61ec457822dd14966afa0752340ae8ce180a1 (patch)
treeae8adb1ad82c717868e551e699fd3cf3bb290089 /script/brave/log.lua
parentc63b2e404d8d2bb984afe3678a5ba2b2836380cc (diff)
downloadlua-language-server-4ca61ec457822dd14966afa0752340ae8ce180a1.zip
no longer beta
Diffstat (limited to 'script/brave/log.lua')
-rw-r--r--script/brave/log.lua54
1 files changed, 54 insertions, 0 deletions
diff --git a/script/brave/log.lua b/script/brave/log.lua
new file mode 100644
index 00000000..18ea7853
--- /dev/null
+++ b/script/brave/log.lua
@@ -0,0 +1,54 @@
+local brave = require 'brave'
+
+local tablePack = table.pack
+local tostring = tostring
+local tableConcat = table.concat
+local debugTraceBack = debug.traceback
+local debugGetInfo = debug.getinfo
+local osClock = os.clock
+
+_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', {
+ level = level,
+ msg = str,
+ src = info.source,
+ line = info.currentline,
+ clock = osClock(),
+ })
+ 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