Is it possible to enable @debug messages selectively, for a specific file or function within a module? I see in the docs that
Message filtering can be influenced through the JULIA_DEBUG environment variable, and serves as an easy way to enable debug logging for a file or module.
(emphasis mine).
But I can’t find any examples of enabling it for a file, and my attempts haven’t worked. I’d like to not enable debugging messages for the entirety of my module, it’s pretty big and that’s a whole lot of debugging.
Here I’ll introduce two packages that can meet your needs.
Memento.jl. Memento is a flexible hierarchical logger where the hierarchy is defined by dot-delimited names. You can create module/file/function–scoped child loggers like getlogger("MyPkg.file.parse") or getlogger("MyPkg.fn.step!") and set their levels/handlers independently, without tying them to real paths or reflection. This gives you practical per-file/per-function control (just choose unique names); if you need finer rules, add Filters that inspect record metadata before a handler emits.
HierarchicalLogging.jl. HierarchicalLogging provides a Base.Logging-compatible tree of loggers keyed by dot names. You attach loggers to nodes (e.g., MyPkg.file.parse, MyPkg.fn.step!) and set minimum levels per node, with optional cascading via min_enabled_level!. That lets you run different levels per module/file/function simply by how you name/attach the nodes; you can also leverage standard metadata (module/file/line) if you prefer routing by emitted fields.
It definitely works for files in Base, for example JULIA_DEBUG=loading enables logging only for base/loading.jl, which is very useful for debugging precompilation cache misses.