Is there anything in julia at the moment, that allows statements to be printed that give an idea of what is going on inside a function, only if the script or function is run during a debug mode?
@debug println("Finished looping: i is $(i)")?
I just wrote my own trivial macro for that, which I use in conjunction with my little https://github.com/ScottPJones/StringUtils.jl (unregistered) package to get easily formatted debugging output.
const global debug = [false]
:( debug && println($(esc(str))) )
and in the code I have things like:
@deb(u"These are floats: \%8.2f(1.2345), \%8.3f(9.8765)")
and get nicely formatted output like:
These are floats: 1.23, 9.877
Then to enable debugging output of that module, I simple do:
Foo.debug = true.
@maleadt has implemented something similar for
CUDAdrv at CUDAdrv.jl/logging.jl at 03c7b94fb0072b217089ac86e80863e418c1799a · JuliaGPU/CUDAdrv.jl · GitHub
The idea is that you can start a Julia session with,
TRACE=1 julia --compilecache=no ./program.jl
--compilecache=no is necessary since
TRACE=1 is checked at compilation time and if
CUDAdrv is precompiled, we can’t switch debugging on.
We do very much need a lightweight, extensible standard way of doing info/debug logging in the standard library.
I’ve been using Logging.jl for this type of thing, with good results.
We ended up coming up with our own macros for logging also (with a bit of weird syntax magic I got from my friends on the JuliaLang/julia - Gitter Gitter chat room.
The macro doesn’t execute the anonymous function, but instead uses it to get the
__LINE__ information, which unfortunately is otherwise unavailable from within a macro call (actually just one of them isn’t).
We use other flags and level settings to determine whether the macros 1) get compiled into the code (for warning and info messages) or 2) it is logged or not (run-time check based on level/flags)