Home : 19 July 2015


Using Loggly On Elastic Beanstalk

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.

Configure App

Add the syslogger gem to your Gemfile.

# Gemfile
gem 'syslogger', '~> 1.6.0'

In 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)

Create Loggly Account

Go sign up for a Loggly account and create a customer token.

Configure Container Environment

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_ACCOUNT and LOGGLY_AUTH property names.

Customise Container

Add the following configuration to loggly.config in the .ebextensions directory in the root of your app.

# .ebextensions/loggly.config
    mode: "000755"
    owner: root
    group: root
    content: |
      su --command="python /tmp/configure-syslog.py setup --auth $LOGGLY_AUTH --account $LOGGLY_ACCOUNT --yes"

      wget -q -O /tmp/configure-syslog.py https://www.loggly.com/install/configure-syslog.py
    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.

Wrap Up

Re-deploy your app to Elastic Beanstalk and watch as your logs begin appearing in Loggly.