Selectively enable debug level logging with a custom `global_logger`

Hello! I’m at a loss on how to selectively enable debug logging when overriding a global logger. If I override the global_logger like this:

ConsoleLogger(stdout, Logging.Info) |> global_logger

then setting ENV["JULIA_DEBUG"]="MyModule" doesn’t have any effect because the min_level is INFO. However, if I set min_level to DEBUG - all of the debug statements get logged. JULIA_DEBUG seems to have no effect…

Would be grateful for any pointers!

the ENV["JULIA_DEBUG"] thing is a mess, that @Chris_Foster have been talking about replacing for years.
See DemuxLogger does not work with JULIA_DEBUG? · Issue #20 · oxinabox/LoggingExtras.jl · GitHub

I suggest LoggingExtras is a much better solution.
I would do something like (not tested).

using LoggingExtras

global_logger(EarlyFilteredLogger(ConsoleLogger(stdout, BelowMinLevel)) do log
    # Keep any messages from MyModule or of Info level or greater
    log._module == MyModule || log.level >= Info
1 Like