Search code examples
debuggingjuliajuno-ide

How to enable debugging messages in Juno (Julia editor)


The Julia docs are pretty clear on how to enable debugging messages from @debug macros, i.e. run export JULIA_DEBUG=mymodule or export JULIA_DEBUG=all on the command line before starting Julia. However, is there an easy way to enable debugging from within the Juno, or, more generally, while Julia is running?

I tried fiddling with Base.CoreLogging.disable_logging , Base.CoreLogging.BelowMinLevel and Base.CoreLogging._min_enabled_level without success.

I know I can set env variables for Julia in the Juno settings. But that's kind of annoying to work with as it requires restarting Julia. I really want to have the following workflow while working interactively:

  1. Enter a line in the REPL
  2. Stumble upon a bug from your own code that you didn't see coming.
  3. Enable debugging.
  4. Run that line again.
  5. See the debug logs.
  6. Fix your code.
  7. Disable debug logging again.

Which I think is nicer than the common practice of commenting and un-commenting printf everywhere.


Solution

  • Enable @debug everywhere (this will only affect code loaded after running the following expression):

    julia>ENV["JULIA_DEBUG"] = "all"
    

    Enable @debug in file foo.jl (according to docs, haven't tested this):

    julia>ENV["JULIA_DEBUG"] = "foo"
    

    Disable @debug:

    ENV["JULIA_DEBUG"] = ""
    

    important note: macros are evaluated when code is loaded. So the tricks above will only have effect on code that is loaded after changing the value of JULIA_DEBUG. So after setting it to e.g. all, nothing will have changed. Reload the modules you want to @debug.