-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Description
ElixirForum Discussion
The current :console
logger backend doesn't support injecting custom formatters.
Issue
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).
Proposal
Let's create a behavior for formatters, break out the default formatter from :console
, and determine formatters from configuration.
We might also want to break out common functionality into the utils module to help with the creation of custom formatters. This would include things like handling metadata.
config :logger,
backends: [:console]
config :logger, :console,
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.
It is not possible in the current implementation, we would have to reimplement the whole backend. - Jose
I'm also hoping this creates a pattern for other elixir logger projects to follow.