-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDebug.lua
149 lines (132 loc) · 3.93 KB
/
Debug.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
local _, Oken = ...
local Debug = Oken:RegisterModule("Debug")
-------------------------------------------------------------------------------
-- Config
-------------------------------------------------------------------------------
local debug_defaults = {
profile = {
debug = false,
}
}
local debug_config = {
title = {
type = "description",
name = "|cff64b4ffDebug",
fontSize = "large",
order = 0,
},
desc = {
type = "description",
name = "Development and debug functionalities.\n",
fontSize = "medium",
order = 1,
},
debug = {
type = "toggle",
name = "Enable DEBUG logging",
descStyle = "inline",
width = "full",
get = function() return Debug.settings.debug end,
set = function(_, v) Debug.settings.debug = v end,
order = 6
},
debug_desc = {
type = "description",
name = "|cff999999Enable logging of DEBUG-level events.\nThis may cause wasted CPU usage if you do not care about debug events.\n",
order = 7,
width = "full"
},
ref = {
type = "header",
name = "Module reference",
order = 1000,
},
docs = Oken.Config:MakeDoc("Public API", 2000, {
{":Dump ( obj )", "Dumps the given object in the chat."},
}, "Oken"),
levels = Oken.Config:MakeDoc("Logging API", 3000, {
{":Error ( label , data )", "Critical error preventing the addon from producing any results at all."},
{":Warn ( label , data )", "Serious error that does not prevent the addon from performing its task."},
{":Info ( label , data )", "Informational data that may be useful to a moderately advanced users."},
{":Debug ( label , data )", "Debug data useful only for developers."},
}, "Oken"),
events = Oken.Config:MakeDoc("Emitted events", 4000, {
{"_LOG ( level , label , data )", "Emitted when a logging function is called.\nLevel will be \"ERROR\", \"WARNING\", \"INFO\" or \"DEBUG\"."},
}, "OKEN_DEBUG"),
}
-------------------------------------------------------------------------------
-- Life-cycle
-------------------------------------------------------------------------------
function Debug:OnInitialize()
self.db = Oken.db:RegisterNamespace("Debug", debug_defaults)
self.settings = self.db.profile
Oken.Config:Register("Debug", debug_config)
end
-------------------------------------------------------------------------------
-- Utils
-------------------------------------------------------------------------------
do
local colors = {
["string"] = "fffff569",
["number"] = "ffff7d0a",
["table"] = "ffabd473",
["function"] = "ff69ccf0",
}
function Debug:TypeColor(type)
return colors[type] or "ff00ff96"
end
end
-------------------------------------------------------------------------------
-- Dump
-------------------------------------------------------------------------------
-- Dump helper
function Oken:Dump(t)
local dump_cache = {}
local function to_string(v)
local tpe = type(v)
local prefix = "|c" .. Debug:TypeColor(tpe)
local suffix = "|r"
if tpe == "string" then
prefix = prefix .. "\""
suffix = "\"" .. suffix
end
return prefix .. tostring(v) .. suffix
end
local function sub_dump(t, indent)
local t_str = to_string(t)
if dump_cache[t_str] then
print(indent .. "*" .. t_str)
else
dump_cache[t_str] = true
if type(t) == "table" then
for pos, val in pairs(t) do
if type(val) == "table" then
print(indent .. to_string(pos) .. " => " .. to_string(val) .." {")
sub_dump(val, indent .. (" "):rep(4))
print(indent .. "}")
else
print(indent .. to_string(pos) .. " => " .. to_string(val))
end
end
else
print(indent .. t_str)
end
end
end
sub_dump(t, " ")
end
-------------------------------------------------------------------------------
-- Logging
-------------------------------------------------------------------------------
function Oken:Error(label , data)
error("NYI")
end
function Oken:Warn(label , data)
error("NYI")
end
function Oken:Info(label , data)
error("NYI")
end
function Oken:Debug(label , data)
error("NYI")
end