Propagate the caller's Logger level to preload tasks - #4766
Merged
josevalim merged 1 commit intoJul 26, 2026
Merged
Conversation
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
marked this pull request as ready for review
July 25, 2026 17:48
Member
|
💚 💙 💜 💛 ❤️ |
Contributor
Author
|
Thank you! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Preloads run in parallel tasks (
Task.async_streaminEcto.Repo.Preloader), and those tasks don't inherit the caller's per-process Logger level. SoLogger.put_process_level/2(orput_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/1andput_process_level/2are 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.