halostatue

halostatue

We were having a discussion at work about logging:

I was thinking about the pros and cons of adding stack traces to log metadata last week, and the difference between the messages we log for helping operate the system and the messages which get presented to the real end user (see kevlinhenney on twitter for endless examples of diagnostics ending up in user interfaces).I was wondering about having a function to automatically bundle stacktrace information into a log message so we could do something like:

# stripped down code to handle a failure # e.g. {:error, posix} = File.open(filename)
message = "Failed to open #{filename}" #{:file.format_error(posix)}
OurLogger.error(message)
{:error, message}

And OurLogger could massage and add stacktrace: Process.info(self(), :current_stacktrace) to the metadata. The log formatter could then display stack traces for error and higher?Then the application sending a result to the eventual human would have to make sure it presented an appropriate message for the user.

This sounds…possible, but it feels like it would be very expensive to achieve. Obviously, we’d never implement this without benchmarking getting a stacktrace, but what I wonder is whether cost is that high?

If it’s low, would there be a reason to add this to Elixir’s logger by default?

Showing Posts 1 to 3

NobbZ

NobbZ

As implicit stack traces have been removed in favor of explicit stacktraces due to their cost, it is safe to assume that it will be far to expensive to always log them.

For errors and above though, I think it totally depends on the error. Are you really able to learn anything new from an attached stacktrace, or is File/Function metadata already enough, as there are basically only 2 or less pathes that this function will ever be called?

When you log an error or above, why do you prefer to log the error, rather than crash? Error for me means “this is a condition the process can not recover from, it will not proceed”, while “above error” for me even means “this application is unable to recover from the condition, it will shut down”.

hauleth

hauleth

If you log anything above error and you do not crash at least process, then I think that you use logging system incorrectly.

To extend a little on levels error and above:

halostatue

halostatue OP

@NobbZ The example given was illustrative only. There are plenty of cases where something is an error, but potentially recoverable—especially when dealing with external systems (this is mostly what our services do).

In general, I agree with @hauleth’s levels, although to me alert is more right here, right now.

Thanks for the thoughts on this; it confirms the feeling that I had on the cost of stacktrace acquisition.

— All posts loaded —

Where Next? Top

Trending in Discussions Top

cblavier
Hey there, It’s been more than a year since we started using LiveView as our main UI library and building a whole library of UI componen...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New
axelson
Hi there! :wave: @frigidcode and I (but mostly him) have been running an Elixir Book club, we’re almost done with Designing Elixir Syste...
New
achempion
I’ve been using Emacs as my main code editor for more than a two years. It’s a custom build version although I’ve tried doom emacs and sp...
New
budgie
I love Elixir. It’s one of 2 programming languages I’ve ever fallen in love with. But I don’t use it anymore. Serverless was the promis...
New
jtormey
Lately I’ve been thinking about how to organize components as a LiveView application grows. One of the pain points I’ve found (for myself...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
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
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New
georgeguimaraes
Just published claude-code-elixir, a plugin marketplace for Claude Code with Elixir support. These are the plugins I’ve been using for my...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews