You can use the Logglier library to send Ruby logs to Loggly. It can send Ruby on Rails logs over HTTP/S to Loggly and accepts multiline and JSON events. For alternatives, please see the Advanced Options section below.
Ruby Logging Setup
- Install Logglier
Open Gemfile in your application. It should be present in the root directory of your application.
Add the following statement to the Gemfile to include the logglier gem in your application
gem 'logglier', '~> 0.2.11'
Install the gem using bundle
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 'logglier' config.logger = Logglier.new("https://logs-01.loggly.com/inputs/TOKEN/tag/ruby/", :threaded => true)
- TOKEN: your customer token from the source setup page
Now use the logger in your application.
logger.info("Beavers signal an alarm by slapping the water with their tail.")
Restart your rails application and visit a page so that it sends this event to Loggly.
Search Loggly for events with the ruby 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.
Advanced Ruby Logging Options
- Logglier GitHub – Additional options for Rails syslog, TLS, and more.
- Rails Logging – Instructions specific for Rails logging with Loggly.
- Loggly Libraries Catalog – See more options of sending Ruby Logs to Loggly.
- Logging Fast – If speed is a concern, then you should pick a fast transport protocol. Here is their speed ranking from fastest to slowest:
- Syslog UDP
- Syslog TCP
- Threaded HTTP
- Threaded HTTPS
- Blocking HTTP
- Blocking HTTPS
Syslog is the fastest because it’s the most efficient protocol and the syslog daemon runs asynchronously with it’s own queuing system (and optionally TLS encryption).
UDP uses a simple connectionless transmission model with a minimum of protocol mechanism. There is no guarantee of delivery, ordering, or duplicate protection.
Threaded won’t block your app but it can use up more memory and stack space. Blocking is the slowest because your app will wait for the data to be received by Loggly.
HTTPS is slower than HTTP because it requires an extra round trip to setup the secure connection.
Troubleshooting Ruby Logs
- Wait a few minutes in case indexing needs to catch up.
- See if you have included the correct version of Logglier.
- See our HTTP Troubleshooting Guide to verify HTTP events are being sent to Loggly.
- Search or post your own Ruby logging or Ruby on Rails logging questions in the community forum.