# Enable debug logging for one file or one function in a module

**URL:** <https://discourse.julialang.org/t/enable-debug-logging-for-one-file-or-one-function-in-a-module/132423>\
**Category:** General Usage\
**Tags:** debugging, logging\
**Created:** [September 16, 2025, 2:08am UTC](https://discourse.julialang.org/t/enable-debug-logging-for-one-file-or-one-function-in-a-module/132423 "2025-09-16T02:08:18Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ken\_Williams](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ken_williams/32/5289_2.png) [@Ken\_Williams](https://discourse.julialang.org/u/Ken_Williams)\
**Post date:** [September 16, 2025, 2:08am UTC](https://discourse.julialang.org/t/enable-debug-logging-for-one-file-or-one-function-in-a-module/132423/1 "2025-09-16T02:08:18Z")

</div>

Is it possible to enable `@debug` messages selectively, for a specific file or function within a module? I see in [the docs](https://docs.julialang.org/en/v1/stdlib/Logging/) that

> Message filtering can be influenced through the [`JULIA_DEBUG`](https://docs.julialang.org/en/v1/manual/environment-variables/#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.

---

<div class="post-metadata">

**Author:** ![karei](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/karei/32/214809_2.png) [@karei](https://discourse.julialang.org/u/karei)\
**Post date:** [September 16, 2025, 5:18am UTC](https://discourse.julialang.org/t/enable-debug-logging-for-one-file-or-one-function-in-a-module/132423/2 "2025-09-16T05:18:10Z")

</div>

No.

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 `Filter`s 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.

---

<div class="post-metadata">

**Author:** ![Ken\_Williams](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ken_williams/32/5289_2.png) [@Ken\_Williams](https://discourse.julialang.org/u/Ken_Williams)\
**Post date:** [September 16, 2025, 3:08pm UTC](https://discourse.julialang.org/t/enable-debug-logging-for-one-file-or-one-function-in-a-module/132423/3 "2025-09-16T15:08:40Z")

</div>

Thanks, I’ll check those out.

Should the docs be corrected to remove the “for a file” part, then?

---

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [September 17, 2025, 7:53am UTC](https://discourse.julialang.org/t/enable-debug-logging-for-one-file-or-one-function-in-a-module/132423/4 "2025-09-17T07:53:15Z")

</div>

> [@Ken\_Williams](#):
>
> Is it possible to enable `@debug` messages selectively, for a specific file

It definitely works for files in `Base`, for example `JULIA_DEBUG=loading` enables logging only for [`base/loading.jl`](https://github.com/JuliaLang/julia/blob/067b0133a8ec3f5c81d89525cd6cb4f25df6cb9c/base/loading.jl), which is very useful for debugging precompilation cache misses.

---

<div class="post-metadata">

**Author:** ![Ken\_Williams](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ken_williams/32/5289_2.png) [@Ken\_Williams](https://discourse.julialang.org/u/Ken_Williams)\
**Post date:** [September 19, 2025, 2:45pm UTC](https://discourse.julialang.org/t/enable-debug-logging-for-one-file-or-one-function-in-a-module/132423/5 "2025-09-19T14:45:08Z")

</div>

Do we know what criteria it uses for checking whether a file matches the setting of `JULIA_DEBUG`? Is it just a substring match or something?

---

<div class="post-metadata">

**Author:** ![cjdoris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cjdoris/32/213133_2.png) [@cjdoris](https://discourse.julialang.org/u/cjdoris)\
**Post date:** [September 19, 2025, 3:46pm UTC](https://discourse.julialang.org/t/enable-debug-logging-for-one-file-or-one-function-in-a-module/132423/6 "2025-09-19T15:46:56Z")

</div>

It’s documented here: [Logging · The Julia Language](https://docs.julialang.org/en/v1/stdlib/Logging/#Environment-variables)

A log message has it’s originating module and a group. The group by default is the base of the filename but can be overridden.

The entries in `JULIA_DEBUG` match either the module name or the group.

---

<div class="post-metadata">

**Author:** ![Ken\_Williams](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ken_williams/32/5289_2.png) [@Ken\_Williams](https://discourse.julialang.org/u/Ken_Williams)\
**Post date:** [September 22, 2025, 3:33pm UTC](https://discourse.julialang.org/t/enable-debug-logging-for-one-file-or-one-function-in-a-module/132423/7 "2025-09-22T15:33:09Z")

</div>

Got it, thanks. It seems like it takes a lot of mental pulling-together to connect the dots on how to do this, maybe that could be clarified or cross-referenced a bit better?
