FANDOM


--[[
{{Helper module|name=Logger
|fname1=log(table)
|ftype1=table
|fuse1=Logs the contents of the table to the console (does not expand subtables).
 
Notes:
* Assumes all table indices can be represented as strings - using functions or tables as indices will result in non-specific log entries
* This is best used by adding <code>p.logger = require('Module:Logger')</code> to the top of the module, then calling <code>p.logger.log(obj)</code> in the debug console on the module page
* This module will only print to the debug console - it has no use when used outside of the development environment and should be removed/commented out before saving
|fname2=deep_log(table)
|ftype2=table
|fuse2=Logs the contents of the table to the console, expanding subtables. See above notes.
}}
--]]
-- <nowiki>
--
-- 
--
 
local p = {}
 
function p.log(obj)
	if type(obj) ~= 'table' then
		mw.log('Argument is a '..type(obj)..', not a table')
		return
	end
	for i,v in pairs(obj) do
		mw.log(tostring(i)..'\t'..tostring(v))
	end
end
 
function deep_log(obj, prefix)
	local pfix = ''
	if prefix then
		pfix = prefix..'.'
	end
 
	for i,v in pairs(obj) do
		mw.log(string.format('%s%s\t%s',pfix,tostring(i),tostring(v)))
		if type(v) == 'table' then
			deep_log(v,pfix..tostring(i))
		end
	end
end
 
 
function p.deep_log(obj)
	if type(obj) ~= 'table' then
		mw.log('Argument is a '..type(obj)..', not a table')
		return
	end
	deep_log(obj, nil)
end
 
return p

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.