dogweather

dogweather

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?

Most Liked

garrison

garrison

The problem is not on the logging side, it’s on the filtering side (output, not input). There are many techniques to filter logs, ranging from a text-based approach (grep) to complex filtering on structured or semi-structured logs. There are platforms that support SQL, even.

I don’t know if there are any tools for this for development, though. Funny, recently I was watching an old stream from one of the Tigerbeetle devs debugging a simulation failure. Since the simulator in full debug mode generates several gigs of logs he had written a tool to filter them live in his editor. It looked to be pretty simple, just some accept/reject filters that recompute a view of the log file. Maybe we need something like that!

But yeah, adding more log levels is never going to solve this IMO.

Last Post!

axelson

axelson

Scenic Core Team

It’s possible to use code to change the log level on a per-module basis. So you could use that to remove logs from other portions of the code base especially if you have a consistent module prefix to use.

Where Next?

Popular in Questions Top

minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New

Other popular topics Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 54996 245
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 44167 214
New

We're in Beta

About us Mission Statement