From fc87521bd165f4d1d273d01749b13b841c61595d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Thu, 19 Sep 2019 21:15:27 +0800 Subject: =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server-beta/src/work/log.lua | 50 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 server-beta/src/work/log.lua (limited to 'server-beta/src/work/log.lua') 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 -- cgit v1.2.3