Skip to content
This repository was archived by the owner on Mar 24, 2025. It is now read-only.

Commit 35fc918

Browse files
committed
finish
1 parent a31658e commit 35fc918

File tree

3 files changed

+79
-0
lines changed

3 files changed

+79
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
local Logger = Class:extend()
2+
3+
local date = os.date
4+
local format = string.format
5+
local stdout = _G.process.stdout.handle
6+
7+
8+
local RED = 31
9+
local YELLOW = 33
10+
local GREEN = 32
11+
local CYAN = 36
12+
13+
local config = {
14+
{'[ERROR] ', RED},
15+
{'[WARNING]', YELLOW},
16+
{'[INFO] ', GREEN},
17+
{'[DEBUG] ', CYAN},
18+
}
19+
20+
function Logger:initialize(Settings)
21+
Settings = Settings or {}
22+
Settings.Debug = Settings.Debug or false
23+
24+
self.Debug = Settings.Debug
25+
end
26+
27+
do -- parse config
28+
local bold = 1
29+
for _, v in ipairs(config) do
30+
v[2] = format('\27[%i;%im%s\27[0m', bold, v[2], v[1])
31+
end
32+
end
33+
34+
35+
function Logger:Log(level, msg, ...)
36+
37+
local tag = config[level]
38+
if not tag then return end
39+
40+
--msg = format(msg, ...)
41+
42+
local d = date("%Y-%m-%d %H:%M:%S")
43+
stdout:write(format('[%s] %s: %s\n', d, tag[2], msg))
44+
45+
return msg
46+
47+
end
48+
49+
function Logger:Error(Msg, ...)
50+
Logger:Log(1, Msg, ... or "")
51+
end
52+
53+
function Logger:Warn(Msg, ...)
54+
Logger:Log(2, Msg, ... or "")
55+
end
56+
57+
function Logger:Info(Msg, ...)
58+
Logger:Log(3, Msg, ... or "")
59+
end
60+
61+
function Logger:Debug(Msg, ...)
62+
Logger:Log(4, Msg, ... or "")
63+
end
64+
65+
return Logger
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
local Logger = Import("ga.cubicinc.logger.LoggerClass")
2+
3+
return Logger
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
local Package = {}
2+
3+
function Package.OnInitialize()
4+
local Logger = Import("ga.cubicinc.logger.Main")
5+
6+
Logger:Info("test")
7+
Logger:Warn("test")
8+
Logger:Error("test")
9+
end
10+
11+
return Package

0 commit comments

Comments
 (0)