ExperimentalGear/scripts/titlescreen/common/logging.lua

35 lines
930 B
Lua

---Return a string representation of where this function was called from
---@param affix? string
---@param stack_level? integer
---@return string
function Where(affix, stack_level)
stack_level = stack_level or 2
local fun_name = debug.getinfo(stack_level, "n").name
local current_file = debug.getinfo(stack_level, "S").source
local current_line = debug.getinfo(stack_level, "l").currentline
--remove redundant path components
current_file = current_file:gsub("([@=]?).*[\\/]skins[\\/]", "%1")
local where = current_file..":"..current_line
if fun_name then
where = where.." ("..fun_name..")"
end
if affix then
where = where..affix
end
return where
end
---Same as game.Log, but prefixed with where the call happened
---@param message string
---@param severity integer
function DetailedLog(message, severity)
game.Log(Where(": ", 3)..message, severity)
end