Skip to content

Proposal: Logger Backends and Formatters #5754

@Ebtoulson

Description

@Ebtoulson

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions