miduo_client/Assets/ManagedResources/~Lua/Common/Debug.lua

107 lines
2.3 KiB
Lua

--输出日志--
function Log(str)
if LogModeLevel == 0 and not AppConst.isSDKLogin then
Util.Log(debug.traceback(str))
end
end
--警告日志--
function LogWarn(str)
if LogModeLevel >= 0 and LogModeLevel <= 1 and not AppConst.isSDKLogin then
Util.LogWarning(debug.traceback(str))
end
end
--错误日志--
function LogError(str)
if LogModeLevel <= 2 and LogModeLevel >= 0 and not AppConst.isSDKLogin then
Util.LogError(debug.traceback(str))
end
end
-- print
function print(str)
Log(str)
end
-- 有颜色的log可自定义
--
function LogRed(str)
Log("<color=#f00>" .. str .. "</color>")
end
function LogGreen(str)
Log("<color=#0f0>" .. str .. "</color>")
end
function LogBlue(str)
Log("<color=#0ff>" .. str .. "</color>")
end
function LogPink(str)
Log("<color=#FF7AD7>" .. str .. "</color>")
end
function LogYellow(str)
Log("<color=yellow>" .. str .. "</color>")
end
function LogPurple(str)
Log("<color=purple>" .. str .. "</color>")
end
--带有颜色的打印 只支持2 4参数个数("red","") ("red","","#FFFFFF","")
function LogColor(...)
local args = { ... }
if #args == 2 then
Log("<color=" .. args[1] .. ">" .. args[2] .. "</color>")
elseif #args == 4 then
Log("<color=" .. args[1] .. ">" .. args[2] .. "</color>" .. " <color=" .. args[3] .. ">" .. args[4] ..
"</color>")
end
end
function PrintBattleTable(tb)
local s = "{"
if tb then
for k, v in pairs(tb) do
-- k
if type(k) == "number" then
s = s .. string.format("[%s]=", k)
elseif type(k) == "string" then
s = s .. string.format("%s=", k)
elseif type(k) == "table" then
s = s .. string.format("[%s]=", "table")
end
-- v
if type(v) == "number" or type(v) == "string" then
s = s .. v .. ","
elseif type(v) == "table" then
s = s .. PrintBattleTable(v)
end
end
end
return s .. "}"
end
-- 打印表
function LogGreenTable(t)
LogGreen(PrintBattleTable(t))
end
-- 打印表
function LogRedTable(t)
LogRed(PrintBattleTable(t))
end
-- 打印表
function LogBlueTable(t)
LogBlue(PrintBattleTable(t))
end
-- 打印表
function LogPinkTable(t)
LogPink(PrintBattleTable(t))
end