-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathLogger.lua
75 lines (60 loc) · 1.41 KB
/
Logger.lua
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
--
-- FS22 - LeaseToOwn mod
--
-- Logger.lua
--
-- @Author: Bodzio528
--
Logger = {}
Logger.__index = Logger
Logger.DEBUG = 1
Logger.INFO = 2
Logger.WARNING = 3
Logger.ERROR = 4
Logger.OFF = 1000
function Logger.create(name)
local self = setmetatable({}, Logger)
self.name = name
self.level = Logger.DEBUG
return self
end
function Logger:setLevel(level)
self.level = level
end
function Logger:print(level, text)
if level < self.level then
return
end
local levelDesc = "ERROR"
if level == Logger.WARNING then
levelDesc = "WARN"
elseif level == Logger.INFO then
levelDesc = "INFO"
elseif level == Logger.DEBUG then
levelDesc = "DEBUG"
end
log("[" .. levelDesc .. "] " .. self.name .. ": " .. text)
end
function Logger:getLevel()
return self.level
end
function Logger:error(text, ...)
self:print(Logger.ERROR, string.format(text, ...))
end
function Logger:warn(text, ...)
self:print(Logger.WARNING, string.format(text, ...))
end
function Logger:info(text, ...)
self:print(Logger.INFO, string.format(text, ...))
end
function Logger:debug(text, ...)
self:print(Logger.DEBUG, string.format(text, ...))
end
function Logger:dump(tbl, indent)
self:debug(string.rep("-", indent) .. " (" .. type(tbl) .. ")")
if (type(tbl) == "table") then
for k, v in pairs(tbl) do
self:debug(string.rep("-", indent + 1) .. " " ..k .. " (" .. type(v) .. ")")
end
end
end