Solution

file_logger = Logger.new(Rails.root.join("log/alternative-output.log")) Rails.logger.extend(ActiveSupport::Logger.broadcast(file_logger))

# using gem 'logglier' loggly = Logglier.new('https://logs.loggly.com/inputs//tag/ruby', threaded: true) Rails.logger.extend(ActiveSupport::Logger.broadcast(loggly))

Logger

ActiveSupport::Logger.broadcast

Rails 3

config/initializers/active_support_logger.rb

require ‘active_support/logger_silence’

include LoggerSilence

Sometimes, it’s required to setup Rails logger for storing logs into several backends. In our case we decided to use Loggly , but also wanted to leave old file-based logging.Despite the actual solution is very simple, it’s hard to find it. The best match on StackOverflow suggests to create some custom proxy class.Now with Rails 4 it’s a real no-brainer. Let’s solve a task from SO – add alternative logging into file:Setting Loggly as additional backend is not much harder:All you need is to provide object which implementsinterface for. In this way, you can add as much logging backends, as you wish.If you are on Rails 3, just copy original active_support/logger.rb into. Also, remove two lines, which don’t work in Rails 3 environment: line 2 with, and line 7 with.Now it can be used as in previous recipes.