Originally Posted by Joviex
I definately use d() for messages, and even if 1 person disables it, no useful infos.
|
You got one thing wrong thought - my Addon / Library has no public method for an Addon to surpress the Debugging Output! That choice is ultimatively up to the User in the Debug Settings and is disabled by Default. No Addon can change that - only the User.
It 's just there in case that you have an faulty Addon installed that doesn't use d() properly and spams the Chat Window with Debug-Messages and you want to disabled that output without disabling the Addon itself or having knowdlege in developing till the Addon-Developer updates his/her Addon. Thats the basic idea behind that Feature.
I really would like to add an option to disable / enable Hooks but there is no way to access the SaveData before the Addon has been completely loaded (and hooking at that point would be to late)
.
Originally Posted by Joviex
I almost feel there should be a way to hook the chat output with various log levels, just like any standard logger.
log.debug()
log.error()
|
Well that 's what I'm trying to do. It 's just called Buffers instead of Log Levels or Filters. I think I'll extend d() like explained above and add an public masked method "LibDebug.log(msg, buffer)". See this example for an explanation or better said usage example:
Lua Code:
-- This will create LibDebug.Buffer.LootDrop_Messages
LibDebug.AddBuffer("LootDrop_Messages")
-- This will output it's Message in the ChatWindow and store it in LibDebug.Buffer.LootDropMessages
LibDebug.log("Hello this is my first Message", "LootDrop_Messages")
-- This will just add your Message to your Buffer and not output it
LibDebug.AddMessage("Hello this is my second Message", "LootDrop_Messages")
-- Would be the same a LibDebug.log()
d("Hello this is my second Message", "LootDrop_Messages")
-- This would output it's Message and store it as default in LibDebug.Buffer.DEBUG
d("Hello this is my third Message")
-- This would just output it's Message and NOT store it
LibDebug.d("Hello this is my fourth Message")
-- This would copy the current buffer of LootDrop_Messages in MyOutput
local MyOutput = LibDebug.GetBuffer("LootDrop_Messages")
-- Which would for example look like this:
MyOutput = {
"Hello this is my first Message",
"Hello this is my second Message",
"Hello this is my third Message"
}
-- Or you could just output the Buffer at once if you need no further logic (uses LibDebug.d internally)
LibDebug.PrintMessages("LootDrop_Messages")
-- Would output it to the ChatWindow like this:
-- Hello this is my first Message
-- Hello this is my second Message
-- Hello this is my third Message
-- This would Flush ( = Clear / Empty ) the Buffer
LibDebug.FlushBuffer("LootDrop_Messages")
-- Which would result in this Output:
local MyEmptyOutput = LibDebug.GetBuffer("LootDrop_Messages")
MyEmptyOutput = {
-- completely empty
}
Now the only thing that 's missing is a proper Filter-Logic your custom Buffer. I'm not sure if I can or would like to do such a thing or if it would limit it 's usefulness as a Library or not. I think I would probably ultimatively leave that to the Addon-Author (for example you).
Meaning I'd never surpressing any other Type of Message then those in DEBUG. So if an Addon-Author is lazy and didn't update his Addon yet and just uses d("My Debug Output") it 's output would get surpressed (but still logged and displayed in /debug!) in the Chat Window. And I repeat only if the User decided to hide them!
Simply said - all one would have to do to make it working with LibDebug is adding one additional Line and one Parameter!
Lua Code:
LibDebug.AddBuffer("MyAddon_Messages")
d("My Debug Output", "MyAddon_Messages")
This output wouldn't be surpressed then - even if the User decided to surpress the default "DEBUG" messages via the Debug Settings.
If he doesn't - nothing changes for him. At all, unless that he'd live with his stuff being hidden from the ChatWindow and moved to /debug - and only if the User decides so. I don't think it can be any simpler or more accepting in terms of migration. I repeat - there is no automatic suppression and no Addon implementing LibDebug can change that Setting automatically.
I'm open to suggestions if you believe I'm wrong with that kind of implementation - however please keep in mind that there 's not only the Developer but ultimatively the User. Meaning one needs some kind of choice (like surpressing bad messages) and the other one needs to easily migrate his code with as less modification as possible - or if he has no time / or doesn't care - no modification at all. After all there 's already a big number of Addons out there that are using d(). That is why I believe hooking into d() somewhat non-intrusive is the best way to get the best of both worlds together without just instantly needing to update like 500+ Addons.