This repository was archived by the owner on Jun 24, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogger.lua
More file actions
46 lines (39 loc) · 1.19 KB
/
logger.lua
File metadata and controls
46 lines (39 loc) · 1.19 KB
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
---@class Logger The class to print logs.
---@alias Logger.LogType
---| "INFO"
---| "WARN"
---| "ERROR"
Logger = {
---Returns a string which represents time and day in game.
---@return string dateString A string which represents time and day in game.
getDate = function ()
return os.day().."-"..textutils.formatTime(os.time(), true)
end,
---Prints log.
---@param logType Logger.LogType The type of log.
---@param color number The color of log characters. Use global "colors" for color name.
---@param message string A string to print.
printLog = function (self, logType, color, message)
write("["..self.getDate().."/")
term.setTextColor(color)
write(logType)
term.setTextColor(colors.white)
print("]: "..message)
end,
---Prints info log.
---@param message string A string to print.
info = function (self, message)
self:printLog("INFO", colors.white, message)
end,
---Prints warning log.
---@param message string A string to print.
warn = function (self, message)
self:printLog("WARN", colors.yellow, message)
end,
---Prints error log.
---@param message string A string to print.
error = function (self, message)
self:printLog("ERROR", colors.red, message)
end
}
return Logger