aquarhead

aquarhead

Why is `:logger` included in extra_applications by default?

Many projects never remove it even though they don’t use Logger at all. I myself always clean out all comments and skeleton code as well as :logger as soon as I generate a new project, unless I intend to use it very soon. But I have seen so many open source projects just leave it there, from my friends’ projects to widely adopted packages to even community standard tools.

While normally this is not a problem for “pure” Elixir projects, it can be tricky when Erlang dependencies are involved. E.g. :lager used to play badly together with Logger, though this situation seems to be well resolved now. My actual problem arose because ejabberd works around this issue by dropping :lager in favor of Logger, but we depend on :lager's file backend to ship logs around. I spent a good part of yesterday just to remove :logger from the extra_applications list of all my dependencies - none of them use Logger. (couldn’t find an obvious way to just remove :logger when building release w/ distillery)

It also doesn’t feel quite clean to have unused dependencies just laying around.

I would like to know what’s reason behind having it by default in newly generated projects? Is there some deep technical reasons? Or is it just to prevent people mistakenly require Logger without starting it up first?

If there’s a better way to solve my case I would like to know as well.

Thanks ahead!

Most Liked

bitwalker

bitwalker

Leader

In Distillery’s case, it used to use Logger, but later shifted to using its own implementation for shell output - it was just never removed from the applications list.

In general I suspect it is there, as you pointed out, to prevent confusion with using Logger when it is not started. This same problem happened all the time with Timex when people would not add it to their applications list, and then call an API which required timezone data (using tzdata which would blow up when not started), so I definitely understand the motivation.

As for projects not playing nicely with Logger, I believe this can be solved with configuration, particularly for use cases like yours by using something like logger_lager_backend. You could also run both Logger and lager side-by-side by configuring Logger not to handle OTP/SASL reports, since I think that is the primary place where conflict is likely to happen. With the new logger module in Erlang’s standard library, I think conflicts between logging libraries will be even less likely, since they will share the same underlying infrastructure, at least as I understand it.

In any case, I’m not advocating for one side or the other, I can see reasons why it is good to include Logger by default, and reasons why maybe it isn’t such a good idea. Ultimately it is still up the library maintainers to “do the right thing”. If a library does depend on Logger, which is common enough, you’ll need to have a strategy to deal with it anyway, so I don’t see changing the default for Elixir projects as really solving the problem you’ve stated.

dimitarvp

dimitarvp

Requiring the programmers to include an app in the extra_applications list is not rocket science. Not sure what they get confused about, every project on GitHub that needs you to do that is clearly communicating it in their README as far as I have seen so far. Every language and platform has specifics. We are paid to be good at delivering working code, and knowing your tools is an intrinsic part of that.

However, if there are projects that would make use of Logger if it exists in the dependencies and fall back to something else if it doesn’t… that might introduce WTFs indeed.

I see both sides’ arguments but IMO the minimalistic approach should be the default.

Where Next?

Popular in Questions Top

vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
logicmason
Hi there, I'm working through my first release with elixir/phoenix. I've built a release with distillery and found that it crashes when I...
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
sacepums
Hey guys. I'm new to elixir and im really stocked about it. But I ran into a bit of problem - I need to convert a date sting, for examp...
New
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
gonzofish
I’m currently trying to understand how to join three tables using Ecto. All the examples I’ve seen use 2, so maybe I’m just missing somet...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
idi527
I’ve been re-reading swift book again and noticed that multiline strings there don’t have a trailing line break, unlike in elixir iex(2)...
New

Other popular topics Top

yurko
Here are few pieces of (common) Linux knowledge that we use for reasonably small one server apps. We use Ubuntu but this should work for ...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
magnetic
Hey :wave:t3: Elixir community, I’ve been learning Elixir, and working on some side projects. My editor of choice is VSCode, and althoug...
New

We're in Beta

About us Mission Statement