Modifying Logger Settings for Specific Elixir Tests

24
clicks
Modifying Logger Settings for Specific Elixir Tests

Source: jasontokoph.com

Type: Post

The author encountered difficulties in testing an Elixir code path that required specific info logs for auditing due to the log level being set to :warning and above in their test environment. To resolve this, they created a macro named log_level that allows temporary changes to the Logger level for specific test blocks. This macro wraps tests inside a describe block, sets up a temporary log level, and restores the original log level afterward. The implementation allows for better auditing in tests but comes with the limitation of potential conflicts with existing describe calls. The author acknowledges this is a personal solution and invites feedback from others.

© HashMerge 2025