summaryrefslogtreecommitdiff
path: root/log/log.lua
blob: 0c1d3bcc62bcc7345b3cfc455fc616f63d995c60 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
local log = {} 
io.stdout:setvbuf("no")

local _format = "%c"
log.dateFormat = function(fmt)
	_format = fmt
end 

log.LEVEL = {
	INFO = 4, 
	DEBUG = 3, 
	WARN = 2, 
	ERROR = 1, 
	NONE = 0
}

local logTag = { 
	[log.LEVEL.INFO]  = "[Info]", 
	[log.LEVEL.DEBUG] = "[Debug]", 
	[log.LEVEL.WARN]  = "[Warn]", 
	[log.LEVEL.ERROR] = "[Error]", 
}

log.level = log.LEVEL.INFO

log.strict = function(level)
	log.level = level
end

log.log = function(level, msg)
	if level <= log.level then 
		local time = os.date(_format, os.time())
		print(time .. logTag[level] .. ":" .. msg)
	end 
end 

log.info = function(msg)
	log.log(log.LEVEL.INFO, msg)
end 

log.debug = function(msg)
	log.log(log.LEVEL.DEBUG, msg)
end 

log.warn = function(msg)
	log.log(log.LEVEL.WARN, msg)
end

log.error = function(msg)
	log.log(log.LEVEL.ERROR, msg)
end 

return log