Ruby Logging

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

  1. Install Logglier
  2. Open Gemfile in your application. It should be present in the root directory of your application.

    vim Gemfile

    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

    bundle install
    

    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)
    

    Replace:

  3. Send a Test Event
  4. 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.

  5. Verify Events
  6. 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.

    tag:ruby
    

    Ruby Logging

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:
    1. Syslog UDP
    2. Syslog TCP
    3. Threaded HTTP
    4. Threaded HTTPS
    5. Blocking HTTP
    6. 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.
Thanks for the feedback! We'll use it to improve our support documentation.


Top