stackify-ruby-logging

Logging handler for sending log messages and exceptions to Stackify. Logging >=2.0.0 <2.2.2 is supported.

Installation

Add this line to your application's Gemfile:

gem 'logging'
gem 'stackify-ruby-logging'

And then execute:

$ bundle install

Note

This stackify-ruby-logging gem will work and tested for the following Ruby versions: 2.1.x, 2.3.x, 2.4.x, 2.5.x
However this gem won't work in ruby version such as 1.9.x/2.0.x.

Usage

Rails

If your application is based on Rails you will add the script below in config/application.rb. For example:

module SampleRailsApp
  class Application < Rails::Application
    # Initialize configuration defaults for originally generated Rails version.
    config.load_defaults 5.2
    ...
    Other code goes here...
    ...
    require 'logging'
    Logging.init

    logger = Logging.logger['sample_logger']
    logger = Stackify::LoggerProxy.new(logger)
    logger.add_appenders \
      Logging.appenders.stdout,   # output log messages to stdout, you can remove this line if you don't want to display to stdout
      Logging.appenders.file(File.join('log', 'development.log')), # output log messages to a log file
      Logging.appenders.stackify(                                  # output log messages to Stackify
        :api_key => '1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ',
        :app_name => 'rails-app',
        :environment => :development,
        :log_level => :info
      )
    config.logger = logger
  end
end

Non-Rails

For using stackify-ruby-logging gem within any Ruby application such as Sinatra add to top of your main file:

require 'logging'
Logging.init

logger = Logging.logger['sample_logger']
logger = Stackify::LoggerProxy.new(logger)
logger.add_appenders \
  Logging.appenders.stdout,
  Logging.appenders.file(File.join('log', 'development.log')),
  Logging.appenders.stackify(
    :api_key => '1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ',
    :app_name => 'sinatra-app',
    :environment => :development,
    :log_level => :info
  )

Log level

You can use the following log levels: :info, :debug, :warn, :error & :fatal.

Troubleshooting

If there are problems, you can enable internal logging of the stackify-ruby-logging. Add debug_log option see the example below:

require 'logging'
Logging.init

logger = Logging.logger['sample_logger']
logger = Stackify::LoggerProxy.new(logger)
logger.add_appenders \
  Logging.appenders.stdout,
  Logging.appenders.file(File.join('log', 'development.log')),
  Logging.appenders.stackify(
    :api_key => '1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ',
    :app_name => 'sinatra-app',
    :environment => :development,
    :log_level => :info,
    :debug_log => File.join('log', 'stackify.log')
  )