Logentries Docs

Find comprehensive guides and documentation to help you start and continue to work with Logentries.


Search results for "{{ search.query }}"

No results found for "{{search.query}}".
View All Results

Logentries supports Logging from Ruby and Ruby on Rails applications


Log in to Logentries and create a new log by clicking the Add New Log button. Now click Manual Configuration button from the list of options. Give your log a name of your choice, select Token TCP and finally click the Register new log button. A token will be displayed in green. Please record it as we will use it later to configure the library.

Install the Library

To install the gem, edit your application Gemfile and add the following line:

 gem 'le'

Then from the command line run the following command to install the gem:

bundle install


Modify your config/environment.rb file by adding

if !Rails.env.development
	Rails.logger = Le.new('LOGENTRIES_TOKEN')
	Rails.logger = Le.new('LOGENTRIES_TOKEN', local: true)

This simply means the gem will log to the console in development environment and Logentries in production.

If you are not implementing Rails.env.development, you can simply initialize a Rails logger using your Logentries’ Token as shown below:

Rails.logger = Le.new('LOGENTRIES_TOKEN')

Optional Settings

If you want to keep logging locally in addition to sending logs to logentries, just add local parameter after the key. By default, this will write to the standard Rails log or to STDOUT if not using Rails:

Rails.logger = Le.new('LOGENTRIES_TOKEN', :local => true)

You may specify the local log device by providing a filename (String) or IO object (typically STDOUT, STDERR, or an open file):

Rails.logger = Le.new('LOGENTRIES_TOKEN', :local => 'log/my_custom_log.log')

If you want the gem to use SSL when streaming logs to Logentries, add the ssl parameter and set it to true:

Rails.logger = Le.new('LOGENTRIES_TOKEN', :ssl => true)

If you want to print debug messages for the gem to a file called logentriesGem.log, add this:

Rails.logger = Le.new('LOGENTRIES_TOKEN', :debug => true)

If you want to use ActiveSupport::TaggedLogging logging, add this:

Rails.logger = Le.new('LOGENTRIES_TOKEN', :tag => true)

You can also specify the default level of the logger by adding a specific level as in the following:

Rails.logger = Le.new('LOGENTRIES_TOKEN', :log_level => Logger::<level>)

For the LOGENTRIES_TOKEN argument, paste the token for the logfile you created earlier in the Logentries UI or empty string for a UDP connection. Additionally, when connecting via UDP, be sure to specify a port using the UDP port parameter:

Rails.logger = Le.new('', :udp_port => 13287)

Replace LOGENTRIES_TOKEN with the token for the logfile we created earlier in the Logentries UI. If you haven’t taken note of the token when creating your log, you can retrieve it by logging in to Logentries. Once logged in, select the host containing the log for which you want to retrieve the token (e.g. from the side bar on the left hand side of the page). All the token-based logs of this host are then displayed with a Token icon on the right hand side. Click this icon to display the token.

Other Ruby on Rails initialization methods including local logging, SSL enabling, and sending log events to DataHub are documented on the Ruby Logentries github page located here:

Also, as current versions of Ruby on Rails maintains a secrets file for storing tokens, the Logentries token can also be stored within that file, and referenced as such:

Rails.logger = Le.new(Rails.application.secrets.logentries_token, local: true)