602f50fc 0da5 11e7 8a95 d48e63c75880

Set up Loggly and Dokku with Rails, Logspout, and Syslog

I recently launched a new Rails app on Digital Ocean using Dokku. I wanted to pipe out my Rails log data to Loggly, and found the documentation on this to be pretty sparse.

This should capture the steps I took to set it up. These steps assume you have a working Digital Ocean droplet with Dokku 0.7.1 or newer, and Rails 5 (though it should work fine with other frameworks that can log to syslog).

# SSH into your dokku box
dokku ssh

# install the logspout dokku plugin
dokku plugin:install https://github.com/michaelshobbs/dokku-logspout.git

# For TLS:
dokku logspout:server syslog+tls://logs-01.loggly.com:6514

# For non-encrypted:
dokku logspout:server syslog://logs-01.loggly.com:514

# optionally install dokku-hostname
# this sets the app name in loggly to your app, instead of docker container guids
dokku plugin:install https://github.com/michaelshobbs/dokku-hostname.git dokku-hostname

# start logspout
dokku logspout:start

# if you have any errors starting, check the docker logs for hints
docker logs logspout

# rebuild your dokku containers
dokku ps:rebuildall

# see if the stream is working (hit a page in your rails app)
dokku logspout:info
dokku logspout:stream

Grab your customer token from Loggly at https://www.loggly.com/docs/customer-token-authentication-token/

or https://MYUSERNAME.loggly.com/tokens

# edit your logspout environment variables
vi /home/dokku/.logspout/ENV

# add your loggly customer token, replacing the < ... > 
SYSLOG_STRUCTURED_DATA=<loggly customer token>@41058

# restart logspout
dokku logspout:stop; dokku logspout:start

If all goes well, you should be able to hit a page in your Rails app and see the log data in Loggly live tail or dashboard.

Comment below if you have questions, comments, or problems setting it up yourself!

← Back to Overview