As a roblox developer, it is too tedious to use print-style debugging.
- They don’t have trivial-to-use formatting capabilities (like python, where everything can format into the
{}
placeholder). - They cannot be enabled/disabled categorically (e.g., something that prints every frame can be helpful for debugging, but you’ll generally want those logs turned off)
This is my immediate problem, but I don’t even use print
these days because I have my own wrapper that lets me use simplified syntax and gives me the features above.
Example syntax
Debug(
"some message with substitutions %s %s %t",
5, --%s casts everything to a string.
nil, --including nil
{ foo = "bar"; } --%t has custom handling to dump tables, optionally recursive
); --> some-prefix: some message with substitutions 5 nil { foo = "bar"; }
--Doing this same logic with a print statement:
print(MY_PREFIX .. string.format("some message with substitutions %s %s %t", tostring(t), tostring(Nil), SomeHelperFunction({ foo = "bar"; })));
The one thing my wrapper lacks is being able to click the log in the output window & jump to the line of code which produced it. Therefore, my request is that we have a lower-level print function which allows specifying the script & line number to which the print statement belongs, in the style of TestService:Message. This would make it easy for me to cut over, and would keep the solution flexible so I can add whatever kind of formatters I want.
Caveats for the nitpicky
- Yes, you can kinda enable/disable prints for an entire file by blasting away the definition of print –
local print = function() end
. You can kinda enable/disable prints categorically (where a single file has multiple categories) by using constants. I still find this tedious.
local PHYSICS_DEBUG = true;
if PHYSICS_DEBUG then print(...); end
- I could work around this problem by making my prints a little more verbose and having my formatter function return a string. Again, more tedium than I want.
PhysicsDebug = ...; --instantiate some wrapper.
if PhysicsDebug.Enabled then print(PhysicsDebug(--[[printf style formatting]])); end
Edit: comments about tostring(nil)
balking were fixed.