onkel-dirtus / logger_file_backend

MIT License
307 stars 128 forks source link

How to set format on backends? #55

Open zhaoyi0113 opened 6 years ago

zhaoyi0113 commented 6 years ago

I am not sure whether this is an issue or a question.

Below is my configuration which works fine:

config :logger, backends: [{LoggerFileBackend, :error_log}]

Now I want to add a format for the log and I am not sure how to do that. I tried a few configuration but none of them work as below. How can I configure the format?

config :logger, backends: [{LoggerFileBackend, :error_log, format: "\n$date $time $metadata $levelpad$message\n"}]

config :logger, backends: [{LoggerFileBackend, :error_log}],
   format: "\n$date $time $metadata $levelpad$message\n"
isaacsanders commented 6 years ago

The second item in the backend declaration pair is the name of the backend, in the case of LoggerFileBackend.

In order to configure the LoggerFileBackend : error_log, for example, one could do the following:

config :logger, backends: [{LoggerFileBackend, :error_log}]

config :logger, :error_log,
  format: "\n$date $time $metadata $levelpad$message\n"
krisleech commented 1 week ago

Is it possible to pass a formater like LoggerJSON.Formatters.Elastic as I want JSON logs to disk.

I already have this:

config :logger, :default_handler,
  metadata: :all,
  formatter: {LoggerJSON.Formatters.Elastic, metadata: :all}

But I still get non-JSON logs. Thanks!

UPDATE: nevermind, I see it is out of scope 👍