logging = {}
local loglevels={
	["SILENT"]=0,
	["FATAL"]=1,
	["ERROR"]=2,
	["WARN"]=3,
	["INFO"]=4,
	["DEBUG"]=5,
	["TRACE"]=6
}
local loglevels_index={}
for k, v in pairs(loglevels) do
	loglevels_index[v]=k
end

-- default log level
local loglevel="INFO"

function logging.setLogLevel(level)
	loglevel=loglevels[level] and level or loglevel
end

logging.setLogLevel("INFO")

local function printLog(severity, ...)
	if (loglevels[loglevel]) >= severity then
		log("[" .. loglevels_index[severity] .. "] ", ...)
	end
end

function logging.fatal(...) printLog(1, ...) end
function logging.error(...) printLog(2, ...) end
function logging.warn(...) printLog(3, ...) end
function logging.info(...) printLog(4, ...) end
function logging.debug(...) printLog(5, ...) end
function logging.trace(...) printLog(6, ...) end
function logging.test(...) printLog(1, ...) end

return logging