[Proposal] Make Logger.Formatter configurable

49 views
Skip to first unread message

Stephan Epping

unread,
Jul 13, 2017, 4:27:31 AM7/13/17
to elixir-lang-core
Use case

I need to convert the log format that is used for `:console` to print in json format. (Because we use a docker syslog backend that forwards `stdout` to logstash). 

Preferred Solution

Ideally, I would give the `:console` backend a custom formatter via config. The custom formatter than just converts the metadata and message to a json string, which is printed by the default `console` backend. But right now the backend relies on `Logger.Formatter` exclusively. 

Alternative

Add a custom backend that in fact intercepts the log message and converts it to json and then forwards it to the `:console` backend. Drawback: one need to somehow start and wrap the `console` backend. 

José Valim

unread,
Jul 13, 2017, 4:43:40 AM7/13/17
to elixir-l...@googlegroups.com
Please see the "Custom formatting" section in the Logger docs: https://hexdocs.pm/logger/master/Logger.html



José Valim
Skype: jv.ptec
Founder and Director of R&D

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-core+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/fd21b80f-93aa-4e8b-8673-b9cc6a00d52d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Stephan Epping

unread,
Jul 13, 2017, 4:57:15 AM7/13/17
to elixir-lang-core, jose....@plataformatec.com.br
Thanks. I was looking at Elixir 1.4 though :(


On Thursday, July 13, 2017 at 10:43:40 AM UTC+2, José Valim wrote:
Please see the "Custom formatting" section in the Logger docs: https://hexdocs.pm/logger/master/Logger.html



José Valim
Skype: jv.ptec
Founder and Director of R&D

On Thu, Jul 13, 2017 at 10:27 AM, Stephan Epping <stepha...@gmail.com> wrote:
Use case

I need to convert the log format that is used for `:console` to print in json format. (Because we use a docker syslog backend that forwards `stdout` to logstash). 

Preferred Solution

Ideally, I would give the `:console` backend a custom formatter via config. The custom formatter than just converts the metadata and message to a json string, which is printed by the default `console` backend. But right now the backend relies on `Logger.Formatter` exclusively. 

Alternative

Add a custom backend that in fact intercepts the log message and converts it to json and then forwards it to the `:console` backend. Drawback: one need to somehow start and wrap the `console` backend. 

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.

Stephan Epping

unread,
Jul 13, 2017, 5:03:54 AM7/13/17
to elixir-lang-core, jose....@plataformatec.com.br
Reply all
Reply to author
Forward
0 new messages