andyc
andyc

Reputation: 525

How to configure lager to send logs to papertrail or loggly

I am building an erlang application and making use of lager — a logging framework written by Basho technologies.

I would like to send logging output to Papertrail, or failing that Loggly.

Can anyone give me some guidance as to how to configure this?

Upvotes: 4

Views: 1252

Answers (2)

Yoan Tournade
Yoan Tournade

Reputation: 713

As @archaelus told, there is currently no lager syslog adapter with remote protocol support.

Another approach seems to use lager to log to a file:

{lager, [
    {handlers, [
        {lager_file_backend, [{file, "info.log"}, {level, info}]}
  ]}

Then uses remote_syslog2 to forward this log file Papertrail.

For that download and install the latest remote_syslog2 binary (instructions).

Add a /etc/log_files.yml config file with:

files: 
  - /path/to/your/app/log/info.log
destination:
  host: logs.papertrailapp.com
  port: 1234
  protocol: tls
pid_file: /var/run/remote_syslog.pid

And finally the remote_syslog2 deamon: sudo remote_syslog

You can also check the documentation page Papertrail has created for centralizing Erlang logs.


For Loggly, there is a dedicated Lager adapter: lager_loggly.

Upvotes: 1

archaelus
archaelus

Reputation: 7129

I was about to suggest using a lager syslog adapter, and configuring that to talk to the syslog input of Papertrail or Loggly, but the Basho syslog adapter only logs to localhost.

However, all is not lost, you can configure the lager syslog adapter to log using a known facility to syslog-ng or rsyslog on the same machine, and have that syslog daemon send the logs to Papertrail. Papertrail has a syslog configuration guide that will tell you how to configure the syslog server.

I would suggest using a facility of local0 or something in the lager syslog adapter, then configure rsylog like this:

local0.*    @logs.papertrailapp.com:1234

The syslog-ng config is more involved:

filter f_erlang { facility(local0); };
destination d_papertrail {
  udp("logs.papertrailapp.com" port(514));
};
log { source(s_local); filter(f_erlang); destination(d_papertrail); };

Upvotes: 3

Related Questions