Logger_formatter.erl

I need to customize the time field format in the logger_std_h handler.
For instance instead of the classical 2023-01-31T15:06:26.556275+00:00 a simpler view like 15:06:26.556.

Probably a simple way to do that is to extend the Config parameter (that is a map) to accept also a new formatter function:

-type config() :: #{chars_limit     => pos_integer() | unlimited,
                    depth           => pos_integer() | unlimited,
                    legacy_header   => boolean(),
                    max_size        => pos_integer() | unlimited,
                    report_cb       => logger:report_cb(),
                    single_line     => boolean(),
                    template        => template(),

                    formatter => fun(atom()) -> {boolean(), list()},

                    time_designator => byte(),
                    time_offset     => integer() | [byte()]}.

In this way I could pass this option map:

#{legacy_header => false,
            colored => true,
            single_line => true,
            template => ["[", level, "] ", time, " ", msg, "\n"],
           formatter => fun(time) -> {true, "11:00 AM"}; (_) -> false end
          }}

If the formatter function returns false we fallback to the current format.

1 Like