Repository navigation
Expand file tree
/
Copy pathLog.lua
More file actions
69 lines (54 loc) · 1.74 KB
/
Copy pathLog.lua
File metadata and controls
69 lines (54 loc) · 1.74 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
local addonName, ns = ...
-- Define log levels
local LOG_LEVELS = {
ERROR = 1,
WARN = 2,
INFO = 3,
DEBUG = 4
}
-- Set the current log level (only logs at or above this level will be printed)
--@debug@
local CURRENT_LOG_LEVEL = LOG_LEVELS.DEBUG
--@end-debug@
--[===[@non-debug@
local CURRENT_LOG_LEVEL = LOG_LEVELS.WARN
--@end-non-debug@]===]
-- Create the Log table in the ns (namespace) table
ns.Log = {}
-- Internal function to handle logging
local function logMessage(level, ...)
local message = ""
for i = 1, select("#", ...) do
local arg = select(i, ...)
message = message .. tostring(arg) .. " "
end
local logLevelValue = LOG_LEVELS[level] or LOG_LEVELS.INFO
-- Only log if the message level is equal or higher than the current log level
if logLevelValue <= CURRENT_LOG_LEVEL then
local color = "|cffffd700" -- Default color is yellow
-- Set color based on level
if level == "ERROR" then
color = "|cffff0000" -- Red for errors
elseif level == "WARN" then
color = "|cffffff00" -- Yellow for warnings
elseif level == "DEBUG" then
color = "|cff00ff00" -- Green for debug messages
elseif level == "INFO" then
color = "|cffffffd7" -- Light yellow for info
end
DEFAULT_CHAT_FRAME:AddMessage(color .. "[" .. level .. "]:|r " .. message)
end
end
-- Define methods for each log level in ns.Log
function ns.Log.error(...)
logMessage("ERROR", ...)
end
function ns.Log.warn(...)
logMessage("WARN", ...)
end
function ns.Log.info(...)
logMessage("INFO", ...)
end
function ns.Log.debug(...)
logMessage("DEBUG", ...)
end