lager_logstash Build Status

Logstash backend for lager

Configuration

Add lager and lager_logstash to rebar.config:

{deps, [lager, lager_logstash]}.

Add configuration to sys.config:

{lager, [{ handlers
, [{ lager_logstash_backend
, [ {host, "logstash_host"}
, {port, 9125}
]
}]
}]
}

Note: Logstash requires timestamps to be in UTC. However, there is no need to do anything special to get this working - lager_logstash does the conversion for you.

Configure a logstash pipeline:

input {
udp {
codec => "json"
port => 9125
}
}
output {
...
}

Supported options

Option Default Acceptable values
host (required) / inet:socket_address() or inet:hostname()
port (required) / inet:port_number()
level info lager:log_level() - including syslog style comparison flags
fields [] [{atom(), jsx:json_term()}] - allows specifying a bunch of extra fields to be included

Output format

All metadata is included as fields. Code like this:

-module foo
-export([bar/0]).
bar () ->
lager:info([{foo, bar}], "Hello ~s", ["world"]).

Would result in JSON like this:

{
"message": "Hello world",
"@timestamp": "2019-01-13T21:33:56.925Z",
"fields": {
"severity": "info",
"foo": "bar",
"application": "otp_application",
"node": "some_node@localhost",
"pid": "<0.13919.0>",
"module": "foo",
"function": "bar",
"line": "6"
}
}

License

Released under the MIT license - please see the LICENSE file.

© 2019 - TruQu