Ebtoulson

Ebtoulson

Proposal: Logger Backends and Formatters

This is kind of a question and a proposal.
I recently looked into switching loggers for a few our phoenix applications from a file logger to a stdout json logger.
While doing some research, I noticed a few different patterns in use. The first was to wrap the existing Logger module and the second was to create a backend.

I don’t think wrapping Logger is ideal since a lot of other packages have dependencies on Logger and could be calling it directly.
This would also require the project owner to be on the lookout for any direct use of the module in any future changes.

Creating a backend seems to be the intended pattern but I think this could be improved. I see a definite separation between outputting (stdio, file, tcp/udp, etc)
and formatting, but this seems to be coupled in a lot of existing logger packages (e.g. logger_json_file_backend).

Have I been looking at this wrong? If not, here’s my proposal: Let’s create a behavior for formatters, break out the default formatter from console, and determine formatters from configuration.

config :logger,
  backends: [{Logger.Backends.Stdout, :stdout_logger}]

config :logger, :stdout_logger,
  level: :debug,
  metadata: [:request_id],
  formatter: Logger.Formatters.Json

Doing something like this while remaining backwards compatible with the existing :console backend and :format configuration might be a little tricky.
We might also want to break out common functionality into the utils module or a helper. This would include things like handling metadata and what not.
Thoughts?

Most Liked

josevalim

josevalim

Creator of Elixir

It seems we do support it today, I just forgot about it. :sweat_smile:

More info: Proposal: Logger Backends and Formatters · Issue #5754 · elixir-lang/elixir · GitHub

josevalim

josevalim

Creator of Elixir

It is not possible in the current implementation, you would have to reimplement the whole backend. Can someone please open up an issue for supporting a custom formatter? I think the current console backend is complex enough to justify the inclusion of a formatting convenience.

ChristopherBui

ChristopherBui

@josevalim This is a pain point we’re also dealing with. Is there a good way to accomplish this with the current implementation?

Where Next?

Popular in Discussions Top

axelson
Decided against including more info in the title, but the gist is that Plataformatec sponsored projects will continue with the assets bei...
New
ricklove
I was just introduced to Elixir and Phoenix. I was told about the 2 million websocket test that was done 2 years ago. From my research, t...
New
crispinb
On reading dhh’s latest The One Person Framework it strikes me that Phoenix with LiveView is already pretty much this. However, never hav...
New
crabonature
I’m still quite new to Elixir. As I understand we got in Elixir “multi guards” as convention to simplify one large guard with or’s?: de...
New
boundedvariable
I am going through the kafka architecture. All the features what the kafka is providing are already in Erlang. I would like hear your opi...
New
PragTob
Hey everyone, this has been on my mind for some time and I’d love your input on it! TLDR: I feel like maps are superioer for storing and...
New
RudManusachi
What configs will make sense to put to runtime.exs? – A bit of how I configure apps: I have generic configs in config/config.exs, dev...
New
chulkilee
Here are the list of HTTP client libraries/wrappers, and some thoughts on HTTP client in general. I’d like to hear from others how they w...
New
Owens
Hello all, I am developing a new mobile app with Flutter frontend and Phoenix backend. The mobile app has real-time task management and c...
New
paulanthonywilson
I like Umbrella projects and pretty much always use them for personal Elixir stuff, especially Nerves things. But I don’t think this is ...
New

Other popular topics Top

malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
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
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
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
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 52341 488
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

We're in Beta

About us Mission Statement