diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2020-11-20 21:57:09 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2020-11-20 21:57:09 +0800 |
commit | 4ca61ec457822dd14966afa0752340ae8ce180a1 (patch) | |
tree | ae8adb1ad82c717868e551e699fd3cf3bb290089 /script/brave/log.lua | |
parent | c63b2e404d8d2bb984afe3678a5ba2b2836380cc (diff) | |
download | lua-language-server-4ca61ec457822dd14966afa0752340ae8ce180a1.zip |
no longer beta
Diffstat (limited to 'script/brave/log.lua')
-rw-r--r-- | script/brave/log.lua | 54 |
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 |