diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-09-19 21:15:27 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-09-19 21:15:27 +0800 |
commit | fc87521bd165f4d1d273d01749b13b841c61595d (patch) | |
tree | 2e143f1fe0509ebfa7536c28180b02478d55783c /server-beta/src/work/log.lua | |
parent | aa4c8b521fc5a8417725a23dfc3d68bc8aae01d3 (diff) | |
download | lua-language-server-fc87521bd165f4d1d273d01749b13b841c61595d.zip |
更新
Diffstat (limited to 'server-beta/src/work/log.lua')
-rw-r--r-- | server-beta/src/work/log.lua | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/server-beta/src/work/log.lua b/server-beta/src/work/log.lua new file mode 100644 index 00000000..4059b461 --- /dev/null +++ b/server-beta/src/work/log.lua @@ -0,0 +1,50 @@ +local brave = require 'pub.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 |