Hanlder logger formatter configuration using version that doesn't support Logger.Formatter.new function

Hello,
Im trying to configure elixir logger formatter configuration for the handler i’ve created.
Iam able to do it in elixir version >= 1.15.0 like below:

config :myapp, :logger, [
  {:handler, :file_log, :logger_std_h,
   %{
     config: %{
       file: ~c"logs/myapp.log",
       filesync_repeat_interval:
         System.get_env("FILE_LOG_SYNC_REPEAT_INTERVAL_IN_MS") |> parse_string_to_integer(5000),
       file_check:
         System.get_env("FILE_LOG_CHECK_INTERVAL_IN_MS") |> parse_string_to_integer(5000),
       max_no_bytes:
         System.get_env("FILE_LOG_MAX_SIZE_IN_MEGABYTES")
         |> parse_string_to_integer(100)
         |> megabytes_to_bytes(),
       max_no_files: parse_string_to_integer(System.get_env("FILE_LOG_MAX_NO_FILES"), 5),
       compress_on_rotate: System.get_env("FILE_LOG_COMPRESS_ON_ROTATE") |> parse_boolean(true)
     },
     formatter:
       Logger.Formatter.new(
         format: {MyApp.Logger.JsonFormatter, :format},
         metadata: [:module, :function, :line, :request_id, :all]
       )
   }}
]

but one of the project im working on is using version=v1.12.0, and the logger in elixir=1.12.0 doesnt support
Logger.Formatter.new function.
I also checked the document for logger handler, it doesnt have handler formatter config metioned.

can anyone help me on this or point me to correct reference?

Thanks !

What you’re configuring above it erlangs :logger library with some elixir helpers. Elixir used to have it’s own logger implementation Logger from times before erlang had :logger. Over time elixir integrated more and more with :logger to allow reuse of knowledge, tools and libraries across the ecosystem. However that means going back in elixir versions means going back in level of integration with :logger by elixir (started with 1.10), and going back far enough eventually supported otp version wouldn’t include :logger (OTP 21+).

Luckily you don’t need Logger.Formatter.new. You can likely also provide it’s return value (print it on 1.15) direct there. The helper just provides some automatic inheritence of related configrations elsewhere.

2 Likes