- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDebugLog.lua
More file actions
Latest commit
125 lines (115 loc) · 4.47 KB
/
Copy pathDebugLog.lua
File metadata and controls
125 lines (115 loc) · 4.47 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
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
-- DebugLog: Silent internal logger (no user-facing messages)
-- All output goes to: WTF/Account/GABHST/SavedVariables/DebugLog.lua
localDEBUGLOG_VERSION=GetAddOnMetadata("DebugLog", "Version") or"?"
DebugLogDB=DebugLogDBor {}
DebugLogDB.errors=DebugLogDB.errorsor {}
DebugLogDB.events=DebugLogDB.eventsor {}
DebugLogDB.arrow=DebugLogDB.arrowor {}
DebugLogDB.vg=DebugLogDB.vgor {}
DebugLogDB.session_start=date("%Y-%m-%d %H:%M:%S")
DebugLogDB.session_count= (DebugLogDB.session_countor0) +1
localMAX=150
localfunctiontrim(tbl)
whiletable.getn(tbl) >MAXdotable.remove(tbl, 1) end
end
localfunctionts() returndate("%H:%M:%S") end
-- Global debug function any addon can call
functionDebugLog(category, msg)
ifnotDebugLogDBthenDebugLogDB= {} end
localcat=categoryor"MISC"
localkey="events"
ifcat=="ERROR" thenkey="errors"
elseifcat=="ARROW" thenkey="arrow"
elseifcat=="VG" thenkey="vg"
end
ifnotDebugLogDB[key] thenDebugLogDB[key] = {} end
table.insert(DebugLogDB[key], ts() .." [" ..cat.."] " .. (msgor"nil"))
trim(DebugLogDB[key])
end
-- Capture all Lua errors
localorigHandler=geterrorhandler()
seterrorhandler(function(msg)
DebugLog("ERROR", msgor"unknown")
iforigHandlerthenorigHandler(msg) end
end)
-- Log key events
localevLogger=CreateFrame("Frame")
evLogger:RegisterEvent("PLAYER_ENTERING_WORLD")
evLogger:RegisterEvent("ADDON_LOADED")
evLogger:RegisterEvent("QUEST_ACCEPTED")
evLogger:RegisterEvent("QUEST_COMPLETE")
evLogger:RegisterEvent("QUEST_FINISHED")
evLogger:RegisterEvent("QUEST_LOG_UPDATE")
evLogger:RegisterEvent("PLAYER_LEVEL_UP")
evLogger:RegisterEvent("PLAYER_DEAD")
evLogger:RegisterEvent("PLAYER_TARGET_CHANGED")
evLogger.questLogCount=0
evLogger:SetScript("OnEvent", function()
ifevent=="PLAYER_ENTERING_WORLD" then
DebugLog("SESSION", "Entered world. Addons loaded. Level: " .. (UnitLevel("player") or"?"))
elseifevent=="ADDON_LOADED" then
-- only log our addons
localaddon=arg1or""
ifaddon=="VanillaGuide" oraddon=="pfQuest" oraddon=="QuestPlates" oraddon=="AutoRogue" then
DebugLog("LOAD", addon.." loaded")
end
elseifevent=="QUEST_ACCEPTED" then
DebugLog("QUEST", "Accepted quest (index: " .. (arg1or"?") ..")")
elseifevent=="QUEST_COMPLETE" then
DebugLog("QUEST", "Quest complete dialog")
elseifevent=="QUEST_FINISHED" then
DebugLog("QUEST", "Quest interaction finished")
elseifevent=="QUEST_LOG_UPDATE" then
localnumEntries=GetNumQuestLogEntries() or0
ifnumEntries~=this.questLogCountthen
DebugLog("QUEST", "Quest log changed: " ..numEntries.." entries")
this.questLogCount=numEntries
end
elseifevent=="PLAYER_LEVEL_UP" then
DebugLog("LEVEL", "Dinged level " .. (arg1or"?"))
elseifevent=="PLAYER_DEAD" then
DebugLog("DEATH", "Player died")
elseifevent=="PLAYER_TARGET_CHANGED" then
localname=UnitName("target")
ifnamethen
DebugLog("TARGET", "Target: " ..name)
end
end
end)
-- Hook pfQuest arrow SetTarget if available
localarrowHook=CreateFrame("Frame")
arrowHook:RegisterEvent("PLAYER_ENTERING_WORLD")
arrowHook:SetScript("OnEvent", function()
arrowHook:UnregisterEvent("PLAYER_ENTERING_WORLD")
ifpfQuestandpfQuest.routeandpfQuest.route.SetTargetthen
localorigSetTarget=pfQuest.route.SetTarget
pfQuest.route.SetTarget=function(node, default)
ifnodethen
DebugLog("ARROW", "SetTarget: " .. (node.titleor"nil") .." spawn=" .. (node.spawnor"nil"))
else
DebugLog("ARROW", "SetTarget: RESET (nil)")
end
returnorigSetTarget(node, default)
end
end
end)
-- Auto-Update Notification (reads LaunchSoloCraft update log)
do
localf=CreateFrame("Frame")
f:RegisterEvent("PLAYER_ENTERING_WORLD")
f:SetScript("OnEvent", function()
f:UnregisterEvent("PLAYER_ENTERING_WORLD")
-- Read update log after 5 seconds
localt=CreateFrame("Frame")
t.elapsed=0
t:SetScript("OnUpdate", function()
this.elapsed=this.elapsed+arg1
ifthis.elapsed>5then
this:SetScript("OnUpdate", nil)
localname=GetAddOnMetadata("DebugLog", "Title") or"DebugLog"
localver=GetAddOnMetadata("DebugLog", "Version") or"?"
DEFAULT_CHAT_FRAME:AddMessage("|cff00ff88[" ..name.."]|r v" ..ver.." loaded")
end
end)
end)
end