Logging in UTC

#config.exs 

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

config :logger, :error_log,
  path: "/home/App/Logs/error.log",
  utc_log: true,
  level: :error

Config is based on recommendations indicated here and here. Despite including utc_log: true all logs are still recorded in local time. What else is needed to change this to UTC time?

Are you not overriding it in in the other configuration files? Like in config/#{Mix.env()}.exs or runtime.exs?

Did you confirmed the timezone in the host?

Try setting utc_log at the logger top-level instead of within the :error_log subsection:

config :logger,
  utc_log: true

Although it looks like LoggerFileBackend doesn’t support utc_log:

LoggerFileBackend supports the following configuration values:
    path - the path to the log file
    level - the logging level for the backend
    format - the logging format for the backend
    metadata - the metadata to include
    metadata_filter - metadata terms which must be present in order to log

Also it seems a bit odd that LoggerFileBackend is reading configurations from :logger, :error_log, generally libraries should read their configuration from their own application’s configuration which would be :logger_file_backend, :error_log in this case.

3 Likes

It’s a logger option, as mentionned in the first post, second link.

Maybe because it is just one of the many possible backend for logger.

That should be the solution.