Skip to content

Propagate the caller's Logger level to preload tasks - #4766

Merged
josevalim merged 1 commit into
elixir-ecto:masterfrom
makoto-developer:preload-tasks-inherit-logger-level
Jul 26, 2026
Merged

Propagate the caller's Logger level to preload tasks#4766
josevalim merged 1 commit into
elixir-ecto:masterfrom
makoto-developer:preload-tasks-inherit-logger-level

Conversation

@makoto-developer

Copy link
Copy Markdown
Contributor

Preloads run in parallel tasks (Task.async_stream in Ecto.Repo.Preloader), and those tasks don't inherit the caller's per-process Logger level. So Logger.put_process_level/2 (or put_module_level) silences the main query but not the queries issued while preloading.

This carries the caller's process level into each preload task. Doing it by default was suggested by the maintainers in elixir-ecto/ecto_sql#602.

Logger.get_process_level/1 and put_process_level/2 are Elixir 1.15+, so the propagation is guarded to keep 1.14 support (it's a no-op there).

Added a test that sets a process level and checks the preload tasks pick it up.

Preloads run in tasks spawned via Task.async_stream, which don't
inherit the caller's per-process Logger level. As a result,
Logger.put_process_level/2 (and put_module_level) silences the main
query but not the queries run while preloading.

Carry the caller's process level into each preload task so the
configured level applies to preload queries too.
@makoto-developer
makoto-developer marked this pull request as ready for review July 25, 2026 17:48
@josevalim
josevalim merged commit 8959c43 into elixir-ecto:master Jul 26, 2026
8 checks passed
@josevalim

Copy link
Copy Markdown
Member

💚 💙 💜 💛 ❤️

@makoto-developer

Copy link
Copy Markdown
Contributor Author

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants