Change default datetime format in Basho lager

472 Views Asked by At

I am implementing lager in my erlang application and was wondering if there was a way to configure the datetime format used? I'd like to default to ISO 8601.

1

There are 1 best solutions below

0
On

The the date and time individually are already in ISO 8601 format from Lager. By using the lager_default_formatter you can get it via the options:

[date, "T", time, "+00:00", " ", ...]    

Which would yield:

2014-08-13T13:19:07.196+00:00 ...

You would need to adjust the timezone designator according to your system settings (which would then unfortunately not be dynamic, but you probably should be running only in UTC anyway).

A complete example of a handler:

{lager_file_backend, [
    {file, "error.log"},
    {level, error},
    {formatter, lager_default_formatter},
    {formatter_config, [
        date, "T", time, "+00:00 ",
        "[", severity,"] ",
        pid, " ",
        message, "\n"
    ]}
]}