-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path98_logging.lua
More file actions
executable file
·45 lines (36 loc) · 811 Bytes
/
Copy path98_logging.lua
File metadata and controls
executable file
·45 lines (36 loc) · 811 Bytes
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
Logger = {}
Logger.__index = Logger
LOG_ERROR = 0
LOG_WARN = 1
LOG_INFO = 2
LOG_DEBUG = 3
local LOGLEVEL_ENUMS = {
[0] = "ERROR",
[1] = "WARN",
[2] = "INFO",
[3] = "DEBUG"
}
debug_level = LOG_DEBUG
function Logger:new(prefix)
local log = setmetatable({}, Logger)
log.prefix = ""
if prefix ~= nil then
log.prefix = prefix
end
return log
end
function Logger:log(level, ...)
if level <= debug_level then
if self.prefix ~= "" then
Printf("%s - %s: %s", LOGLEVEL_ENUMS[level], self.prefix, string.format(...))
return
end
Printf("%s: %s", LOGLEVEL_ENUMS[level], string.format(...))
end
end
function Logger:debug(...)
self:log(LOG_DEBUG, ...)
end
function Logger:info(...)
self:log(LOG_INFO, ...)
end