How to enable debug level loging in code via Logging Package


Is there a way of enable debug level logging in code via Logging api. Log level seems start from Info and other than environment variable there seems to be no way of enabling debug level in code if I am not mistaken. I am newbie in julia.

I would like to state that this logging library is far more mess or weaker than any comparable library in python or ruby. I am suprised about this.

For completeness’ sake, I’ll copy my response to your github issue here as well, so that other people may find it:

You can do ENV["JULIA_DEBUG"] = MyModule to set it to log for calls under MyModule, or to all to log for every module. Likewise, if you set it to nothing, logging will stop. This is also mentioned in the manual, though that text should be expanded a little to document how this actually works. Seems like it just didn’t get documented in RFC: Add support for "all except x" in JULIA_DEBUG by DilumAluthge · Pull Request #32432 · JuliaLang/julia · GitHub

In case someone wants to pick this up, here is the doc file in question and here is how that environment variable special cases certain values and extracts the modules to log. The linked function returns true or false depending on whether or not the environment variable contains a module or not (or is filtered out).

1 Like
julia> using Logging

# Create a logger with Debug level
julia> debug_logger = ConsoleLogger(stderr, Logging.Debug);

# Set the global logger to our debug logger
julia> global_logger(debug_logger);

julia> @debug "hello, world"
┌ Debug: hello, world
└ @ Main REPL[4]:1