Go to most recent revision | Compare with Previous | Blame | View Log
--[[
Addon: Taos Group Ultimate
Author: TProg Taonnor
Created by @Taonnor
]]--
--[[
Global variables
]]--
local TRACE_ACTIVE = true
local DEBUG_ACTIVE = true
local ERROR_ACTIVE = true
local DIRECT_PRINT = true
local CATCH_LUA_ERRORS = false
--[[
Class
]]--
DebugLogger = {}
DebugLogger.__index = DebugLogger
--[[
Class Members
]]--
DebugLogger.Name = "TGU-DebugLogger"
DebugLogger.Buffer = {}
DebugLogger.IsPlayerActive = false
--[[
Trace
]]--
function logTrace(functionName)
if (TRACE_ACTIVE == false) then return end
log("TRACE " .. tostring(functionName))
end
--[[
Debug
]]--
function logDebug(...)
if (DEBUG_ACTIVE == false) then return end
for i = 1, select("#", ...) do
local msg = select(i, ...)
log("DEBUG " .. tostring(msg))
end
end
--[[
Debug
]]--
function logError(...)
if (ERROR_ACTIVE == false) then return end
for i = 1, select("#", ...) do
local msg = select(i, ...)
log("ERROR " .. tostring(msg))
end
end
--[[
Logger
]]--
function log(msg)
DebugLogger.AddMessage(msg)
if (DIRECT_PRINT) then
d(msg)
end
end
--[[
Adds messages to buffer
]]--
function DebugLogger.AddMessage(msg)
if(not msg or DebugLogger.Buffer == nil) then return end
local buf = DebugLogger.Buffer
buf[#buf + 1] = msg
end
--[[
Print buffered messages
]]--
function DebugLogger.PrintMessages()
if(DebugLogger.Buffer == nil) then return end
for i,msg in ipairs(DebugLogger.Buffer) do
d(msg)
end
end
--[[
Prints buffered outputs
]]--
function DebugLogger.OnPlayerActivated(eventCode)
if(DebugLogger) then
DebugLogger.IsPlayerActive = true
DebugLogger.PrintMessages()
end
EVENT_MANAGER:UnregisterForEvent(DebugLogger.Name, EVENT_PLAYER_ACTIVATED)
end
--[[
Catches lua errors
]]--
function DebugLogger.OnLuaError(eventCode, errorOutput)
if (CATCH_LUA_ERRORS == false) then return end
log(errorOutput)
ZO_UIErrors_HideCurrent()
end
--[[
Show catched logs in separate window
]]--
function DebugLogger.ShowLogsWindow()
-- Simple print in chat window
-- TODO: List widget
DebugLogger.PrintMessages()
-- if(_G["DebugLoggerLogsWindow"] == nil) then do return false end end
-- local content = ""
-- for i,msg in ipairs(DebugLogger.Buffer) do
-- content = content .. tostring(msg) .. "\n"
-- end
-- DebugLoggerLogsWindow_EDITBUFFER:SetText(content)
-- DebugLoggerLogsWindow:SetHidden(false)
-- DebugLoggerLogsWindow:SetTopmost(true)
end
--[[
Handles /showlogs command
]]--
function DebugLogger.CommandShowLogs()
DebugLogger.ShowLogsWindow()
end
--[[
Initialize
]]--
function DebugLogger.Initialize()
logTrace("DebugLogger.Initialize")
SLASH_COMMANDS["/showlogs"] = DebugLogger.CommandShowLogs
EVENT_MANAGER:RegisterForEvent(DebugLogger.Name, EVENT_PLAYER_ACTIVATED, DebugLogger.OnPlayerActivated)
EVENT_MANAGER:RegisterForEvent(DebugLogger.Name, EVENT_LUA_ERROR, DebugLogger.OnLuaError)
end