saleyn

saleyn

Logger: custom log formatter

When defining a custom formatter for the Elixir Logger, is there a way for a structured report to be passed to it as a map or a Keyword list instead of being formatted as the iolist?

I.e. for a call Logger.info(%{test: "report"}), I’d like it to be accessible in the formatter in the structured form:

config.ex:

config: :logger, :console,
  format: {MyFormatter, :format}

formatter.ex:

defmodule MyFormatter do
  def format(level, msg, {date, time}, meta) do
     %% The `msg` here is an iolist instead of being passed as a map or Keyword.t
  end
end

Most Liked

LostKobrakai

LostKobrakai

Structured data is only available to erlang :logger handlers, not elixir Logger backends.

tj0

tj0

There’s an entire thread worth of information in there on structured logging. I’ve since updated the module to handle 404’s and exceptions a bit better and been using it in production for a long time now. If interested, I can publish the updated solution somewhere.

Last Post!

tj0

tj0

Where Next?

Popular in Questions Top

ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
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
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New

Other popular topics Top

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
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 31586 112
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
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 40165 209
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 42716 114
New

We're in Beta

About us Mission Statement