Sha256: 2550f365adcc37305f99a1c43f6f116711125ecd2398e1d09853c4586f80dbc7

Contents?: true

Size: 1.47 KB

Versions: 1

Compression:

Stored size: 1.47 KB

Contents

class Slf4rRailtie < Rails::Railtie

  initializer "set_servlet_logger", :after => :initialize_logger do |app|
    if defined?(Slf4r::LoggerFacade)
      @logger = Slf4r::LoggerFacade.new("Rails::Setup")
      @logger.info {
        l = @logger.instance_variable_get('@logger'.to_sym)
        logger_name = l.respond_to?(:java_class) ? l.java_class : l.class
        "setup slf4r logger #{logger_name}"
      }
      app.config.logger = Rails.logger = setup_logger(Rails)
      app.config.action_controller.logger = setup_logger(ActionController)
      app.config.active_record.logger = setup_logger(ActiveRecord)
      app.config.action_view.logger = setup_logger(ActionView) if app.config.action_view.respond_to? :logger=
      app.config.action_mailer.logger = setup_logger(ActionMailer)
      ActiveSupport::Cache::Store.logger = setup_logger(ActiveSupport::Cache::Store)
      clazz = if @logger.instance_variable_get(:@logger).respond_to?(:java_class)
                @logger.instance_variable_get(:@logger).java_class 
              else
                @logger.instance_variable_get(:@logger).class 
              end
    else
      require 'slf4r/wrapped_logger'
      l = Slf4r::LoggerFacade4WrappedLogger.logger = Rails.logger
      l.info "setup slf4r logger wrapper"
    end
  end

  private
  def self.setup_logger(category)
    l = Slf4r::LoggerFacade.new((category == Rails ? "" : "Rails::") + category.to_s)
    @logger.info("setup logger for '#{l.name}'") if @logger
    l
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
slf4r-0.4.2 lib/slf4r/slf4r_railtie.rb