This week I had to configure a Rails app running on Elastic Beanstalk to use Loggly. Since I don’t want anyone to suffer the Elastic Beanstalk documentation more than is necessary, I’ve written this short tutorial should you find yourself tasked with the same challenge. It assumes you already have a Rails app running on Elastic Beanstalk and a general understanding of Rails apps.
Add the syslogger gem to your Gemfile.
config/environments/production.rb configure your app to use
Syslogger for logging. Replace
"your-app-name" with, you guessed it, the name of your application. This allows you to easily see logs from your app in the Loggly web interface using source groups, which is especially useful if you’re using Loggly to aggregate logs from multiple apps.
# config/environments/production.rb config.logger = Syslogger.new("your-app-name", Syslog::LOG_PID, Syslog::LOG_LOCAL7)
Go sign up for a Loggly account and create a customer token.
Go to the Amazon AWS Console and add your Loggly account name and customer token to your Elastic Beanstalk app’s environment using the
LOGGLY_AUTH property names.
Add the following configuration to
loggly.config in the
.ebextensions directory in the root of your app.
# .ebextensions/loggly.config files: "/tmp/loggly_config.sh": mode: "000755" owner: root group: root content: | #!/bin/bash su --command="python /tmp/configure-syslog.py setup --auth $LOGGLY_AUTH --account $LOGGLY_ACCOUNT --yes" container_commands: 01_loggly_dl: command: wget -q -O /tmp/configure-syslog.py https://www.loggly.com/install/configure-syslog.py 02_loggly_config: command: /tmp/loggly_config.sh
This YAML file downloads Loggly’s own syslog configuration script and sets up your container to send your system logs to Loggly. You can audit this script at loggly/install-script.
Re-deploy your app to Elastic Beanstalk and watch as your logs begin appearing in Loggly.