local skynet = require "skynet" local skynet_error = skynet.error local string_format = string.format local table_insert = table.insert local os_date = os.date local os_time = os.time local const_header = { "(T)|", "(D)|", "(I)|", "(W)|", "(E)|", "(F)|" } local header = const_header local function print(level, fmt, ...) skynet_error( os_date("[%m/%d %X]", os_time()), header[level], string_format(fmt, ...)) end local logger_debug = {} function logger_debug.label(name) if name then header = {} for _, v in ipairs(const_header) do table_insert(header, v..name) end else header = const_header end end local function auto_print(level,fmt) local strs_tab = {} local temp_tb = {} local function Save(Obj, floors) if type(Obj) == "number" or type(Obj) == "string" or type(Obj) == "boolean" then if type(Obj) == "boolean" then Obj = Obj and "bool:true" or "false" end table_insert(strs_tab,Obj) if floors == 1 then table_insert(strs_tab,",") end -- table_insert(strs_tab,",\n") elseif type(Obj) == type({}) then if not temp_tb[Obj] then temp_tb[Obj] = 1 local beg_Blank = "" local end_Blank = "" for i = 1, floors do beg_Blank = beg_Blank .. " " end for i = 1, floors-1 do end_Blank = end_Blank .. " " end table_insert(strs_tab,"{\n") for k,v in pairs(Obj) do if tostring(k) ~= "" and v ~= Obj then table_insert(strs_tab,beg_Blank) table_insert(strs_tab,"[\"") table_insert(strs_tab,tostring(k)) table_insert(strs_tab,"\"] = ") Save(v, floors + 1) table_insert(strs_tab,"\n") end end table_insert(strs_tab, end_Blank) table_insert(strs_tab, "}") if floors ~= 1 then table_insert(strs_tab, ",") end end else table_insert(strs_tab,'\"') table_insert(strs_tab,type(Obj)) table_insert(strs_tab,'\",') end end -- 调用 Save 方法进行日志的记录 Save(fmt, 1) local strs = table.concat( strs_tab ) strs = type(fmt)..":"..strs print(level,strs) end local function _logger_debug_interface(fmt, ...) auto_print(1,fmt) end function logger_debug.look(fmt, ...) -- if true then -- return --线上不开放 -- end _logger_debug_interface(fmt, ...) end return logger_debug