You can send your Rails logs to Loggly over syslog. We’re using the lograge gem because it offers better formatting of logs, but it’s not required. We will automatically parse JSON and specific types of rails logs. For alternatives, please see the Advanced Options section below.
Run our automatic configure-linux script below to setup Rails logging and send the logs to Loggly through your syslog daemon.
curl -O https://www.loggly.com/install/configure-linux.sh sudo bash configure-linux.sh -a SUBDOMAIN -u USERNAME
- SUBDOMAIN: your account subdomain that you created when you signed up for Loggly
- USERNAME: your Loggly username
Open your ruby configuration file for rsyslog or create a new one:
sudo vim /etc/rsyslog.d/21-rails.conf
Paste this configuration into the file then save it.
#provides UDP syslog reception $ModLoad imudp $UDPServerRun 514 #Add a tag for Rails events $template LogglyFormatRails,"<%pri%>%protocol-version% %timestamp:::date-rfc3339% %HOSTNAME% %app-name% %procid% %msgid% [TOKEN@41058 tag=\"Rails\"] %msg%\n" local7.* @@logs-01.loggly.com:514;LogglyFormatRails local7.* ~ #discards the messages so they don't end up in /var/log/syslog
- TOKEN: your customer token from the source setup page
Then restart rsyslog so the changes take effect
sudo service rsyslog restart
Open Gemfile in your application. It should be present in the root folder of your application.
Add the following statements to the Gemfile to include the syslogger and lograge gems in your application
gem 'syslogger', '~> 1.6.0' gem 'lograge','~> 0.3.1'
Install these gems in RVM using the following command
Add the following code in your
<environment>.rb config file. You can find it in the config/environments folder present in your application directory structure. You can select .rb file on the basis of your current environment setup. It can be development.rb, test.rb or production.rb
require 'syslogger' config.logger = Syslogger.new("APPNAME", Syslog::LOG_PID, Syslog::LOG_LOCAL7) config.lograge.enabled = true config.lograge.formatter = Lograge::Formatters::Json.new
- APPNAME: your application name
Now use the logger in your application.
logger.info "Hello from Rails!"
Restart your rails application and visit a page so that it starts sending events to Loggly.
Search Loggly for events with the Rails tag over the past 20 minutes. It may take a few minutes to index the event. If it doesn’t work, see the troubleshooting section below.
Click on one of the logs to show a list of Rails fields (see screenshot below). If you don’t see them, please check that you are using one of our automatically parsed formats.
- Syslogger Gem – Rails library for sending application logs to syslog
- Logglier Rails Gem – A ruby gem to send logs over HTTP/S
- Automated Parsing – Describes which types of rails logs we parse automatically
- Lograge – A gem to format rails logs more nicely as JSON
- Loggly Libraries Catalog – New libraries are added to our catalog
- Search or post your own Rails logging questions in the community forum.
If you don’t see any data show up in the verification step, check for these common problems.
Check syslogger configuration:
- If the "bundle install" command fails to execute, check if you are running bundle version 1.11.2 or any older version of bundle. Updating bundle version to 1.16.3 works perfectly. Also, always install Ruby using RVM. This will automatically install/update the bundle version to updated one.
- Wait a few minutes in case indexing needs to catch up.
- Check to see if the 01-ruby-logger.conf is properly created and placed in the proper location. It should be in the /etc/rsyslog.d folder.
- Check that UDP reception is enabled on port 514 in /etc/rsyslog.conf file.
- See our HTTP Troubleshooting Guide to verify HTTP events are being sent to Loggly.
- See our Rsyslog Troubleshooting Guide if the files are not being sent to Loggly.
Still Not Working?
- Search or post your own Rails log questions in the community forum.
When the APM Integrated Experience is enabled, Loggly shares a common navigation and enhanced feature set with the other integrated experiences' products. How you navigate Loggly and access its features may vary from these instructions. For more information, go to the APM Integrated Experience documentation.
The scripts are not supported under any SolarWinds support program or service. The scripts are provided AS IS without warranty of any kind. SolarWinds further disclaims all warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The risk arising out of the use or performance of the scripts and documentation stays with you. In no event shall SolarWinds or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the scripts or documentation.