local u=true local k={}local function F()local u={warnings={}}setmetatable(u,{__tostring=function(u)return("\076\111\103\073\110\102\111\n\t\087\097\114\110\105\110\103\115 \040\037\100\041\058\n\t\t\037\115"):format(#u.warnings,table.concat(u.warnings,"\n\t\t"))end})return u end local c={}function c.capture(c)local b=F()local e=u u=false k[b]=true local i,J=pcall(c)k[b]=nil u=e assert(i,J)return b end function c.warn(F)for u in pairs(k)do table.insert(u.warnings,F)end if u then warn(F)end end return c


local outputEnabled = true
local collectors = {}

local function createLogInfo()
	local logInfo = {
		warnings = {},
	}

	setmetatable(logInfo, {
		__tostring = function(self)
			return ("LogInfo\n\tWarnings (%d):\n\t\t%s"):format(
				#self.warnings,
				table.concat(self.warnings, "\n\t\t")
			)
		end,
	})

	return logInfo
end

local Logging = {}

function Logging.capture(callback)
	local collector = createLogInfo()

	local wasOutputEnabled = outputEnabled
	outputEnabled = false
	collectors[collector] = true

	local success, result = pcall(callback)

	collectors[collector] = nil
	outputEnabled = wasOutputEnabled

	assert(success, result)

	return collector
end

function Logging.warn(message)
	for collector in pairs(collectors) do
		table.insert(collector.warnings, message)
	end

	if outputEnabled then
		warn(message)
	end
end

return Logging
