Elixir logger not able to output Date, only time and log level and msg

# Do not print debug messages in production
config :logger,
  level: :info,
  format: "[$date] [$time] [$level] $message\n",
  backends: [
    {LoggerFileBackend, :error_log},
    {LoggerFileBackend, :info_log},
    :console
  ]

But can only see:

23:33:11.219 [info] 0
23:33:11.220 [info] 0
23:33:11.220 [info] 0
23:33:11.220 [info] 0
23:33:11.221 [info] 0
23:33:11.221 [info] 0

Anything wrong?

You have defined format for :logger application while you need to define it for :console backend:

config :logger, :console, format: "[$date] [$time] [$level] $message\n"
1 Like

Your config is wrong…

Assuming You are using logger_file_backend, which is not mentionned.

You should configure each sub logger, as mentionned in the documentation, probably something like this.

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

config :logger, :error_log, 
  level: :info,
  format: "[$date] [$time] [$level] $message\n",

config :logger, :console ...

# etc

You should also mention where do You get those logs, from the console, or from a file.

1 Like

Kind of make the $date works. but not able to generate the error_log, still working on. will keep you folks post.