Forums » Community Projects

Any way to enable verbose lua debug logs?

Jul 12, 2017 somote link
I'm working on a plugin that is not doing what I want. Lua is not throwing any errors so I am having to debug with nothing to go on. Is there anyway to enable more verbose lua logs so i can debug better?

Thanks in advance.
Jul 12, 2017 draugath link
There isn't anything in the API to produce more verbose error messages for the debugging of a plugin during development besides what you put in it. The DevKit plugin has many tools that are useful for working on plugins, and if you're not already using it, I recommend you check it out.

At present I've forgotten some of the gotchas I've run into over the years that will crash without producing an error. What I usually wind up doing when I have a tricky bug to chase is just placing successive print() calls after every statement or function call that could possibly cause an error, usually with nothing more than a number.

print(1)
print(2)
for i = 1, 10 do
     print(101)
     print(102)
     print(103)
end
print(3)
print(4)

From there I can write more specific debugging messages once I find where it's breaking.
May 05, 2018 Nyscersul link
Hehehehe i do the exact same thing.

To expand on that idea, adding in a print that details which branch/function it is printed by can make things run nicely. Some of my plugins run continuously, and i have them reporting different information during debug, via print, enabling the exact kind of verbosity you so desire. Have the prints work on variables and things you are tracking and your data acquisition is complete.

Tho, most of the prints get removed in the final product, i've actually noticed in some of mr_spucks and draugath's code there is also a debug mode built in, making these print calls go through a function which simply checks if debug mode is on, and only prints in that case.

My own masterpiece, somewhat secret, actually takes control of the entire chat output system, and uses it in ways it was never meant to be used, but i have learned a lot in so doing, including how to debug effectively. Another idea is to get a system notes file to run like errors.log - i used this method in some of my statistical analysis plugins to track down calculational issues.
May 05, 2018 draugath link
Be cautious about using excessive writes to SystemNotes since this is slow and can introduce client-side lag.