Separating app-level debug logging from Ecto debug logging

I have some issues with logging in Elixir / Phoenix / LiveView.

In production, I want to see simple one-line logs for web requests and “important” worker processes that get kicked off.

In development, I usually want to only see my particular debug messages for the issue I’m working on.

Occasionally in development, I also want to see full database query logging.

Lol, this is what gpt-4.1 says:

You’ve clearly articulated the classic Elixir/Phoenix logging pain:

  • :debug is too noisy (full of Ecto queries, etc.)
  • :info is used by Phoenix for web requests, so your own debug/info logs get mixed in
  • You want a way to see your own debug logs in dev, but not get drowned out by Ecto, and you want clean, important logs in prod.

Now, I’ve found that the system by default (and with a few modifications I’ve made) gives:

:debug level — database queries (very high volume & noisy output)
:info level — web requests

So, when I use :debug for my app debugging, those messages get lost in the db query log noise. This is the problem I’m looking to solve.

In search of a solution, I found this documentation:


Levels

The supported levels, ordered by importance, are:

:emergency - when system is unusable, panics
:alert - for alerts, actions that must be taken immediately, ex. corrupted database
:critical - for critical conditions
:error - for errors
:warning - for warnings
:notice - for normal, but significant, messages
:info - for information of any kind
:debug - for debug-related messages

For example, :info takes precedence over :debug. If your log level is set to :info, then all :info, :notice and above will be passed to handlers. If your log level is set to :alert, only :alert and :emergency will be printed.


So, I’m considering using :info for my app-level debug logging, and :notice for production info-type messages — web requests and important events:

  • Change default :info to use :notice. E.g., web requests.
  • I never use :debug, leaving it the province of Ecto and other 3rd party libraries.
  • I use :info only for my app code debugging.
  • In production, I set the level threshold to :notice.

Are there any other alternatives I should consider?