dogweather

dogweather

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?

Showing Posts 1 to 3

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.

martosaur

martosaur

Sounds reasonable. But tbh any more or less used production environment is likely to generate so many logs that plain text view of them is hardly useful. Most log aggregators can filter out logs pretty efficiently, so that would be the first tool I would reach for.

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.

— All posts loaded —

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
jonnycharles
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
dli
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app? Looking for hints regarding: Addi...
New
roeland
Kia ora, We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
bottlenecked
Hi all, I wanted to ask how the community is dealing with post-release steps. Today we have Ecto migrations, which make sure that the db...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews