summaryrefslogtreecommitdiff
path: root/server-beta/src/work/log.lua
blob: 4059b4618a23bc7c5703a4a41418eeeedba85def (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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