Skip to content

Commit

Permalink
fix #3 : when args has nil value
Browse files Browse the repository at this point in the history
  • Loading branch information
hanxi committed Aug 26, 2023
1 parent 2e5387a commit a70ca11
Showing 1 changed file with 25 additions and 24 deletions.
49 changes: 25 additions & 24 deletions lualib/log.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,50 +5,51 @@ local traceback = debug.traceback

local M = {}
local levels = {
debug = 1,
info = 2,
warn = 3,
error = 4,
debug = 1,
info = 2,
warn = 3,
error = 4,
}
local level = config.get("wlua_loglevel", "debug")
local loglevel = levels[level]

function M.is_debug()
if levels.debug < loglevel then return end
return true
if levels.debug < loglevel then return end
return true
end

function M.debug(...)
if levels.debug < loglevel then return end
local tbl = {}
for i,v in pairs({...}) do
if type(v) == "table" then
tbl[i] = util_table.tostring(v)
else
tbl[i] = tostring(v)
end
end
skynet.error("[DEBUG]", table.concat(tbl, " "))
if levels.debug < loglevel then return end
local tbl = {}
for i = 1, select('#', ...) do
local v = select(i, ...)
if type(v) == "table" then
tbl[i] = util_table.tostring(v)
else
tbl[i] = tostring(v) or "nil"
end
end
skynet.error("[DEBUG]", table.concat(tbl, " "))
end

function M.info(...)
if levels.info < loglevel then return end
skynet.error("[INFO]", ...)
if levels.info < loglevel then return end
skynet.error("[INFO]", ...)
end

function M.warn(...)
if levels.warn < loglevel then return end
skynet.error("[WARN]", ...)
if levels.warn < loglevel then return end
skynet.error("[WARN]", ...)
end

function M.error(...)
if levels.error < loglevel then return end
skynet.error("[ERROR]", ...)
skynet.error("[ERROR]", traceback())
if levels.error < loglevel then return end
skynet.error("[ERROR]", ...)
skynet.error("[ERROR]", traceback())
end

function M.log(...)
skynet.error(...)
skynet.error(...)
end

return M

0 comments on commit a70ca11

Please sign in to comment.