Sha256: 9b4fe10f9dedce8501badcfdad2da7b96e97c75c33a03f6980b8d80881723fce

Contents?: true

Size: 1.34 KB

Versions: 2

Compression:

Stored size: 1.34 KB

Contents

module Logster::Rails

  def self.set_logger(config)
    return unless Rails.env.development? || Rails.env.production?

    if defined?(Redis)
      require 'logster/middleware/viewer'
      require 'logster/middleware/reporter'
      require 'logster/redis_store'

      store = Logster.store ||= Logster::RedisStore.new
      store.level = Logger::Severity::WARN if Rails.env.production?

      logger = Logster::Logger.new(store)
      logger.chain(::Rails.logger)
      logger.level = ::Rails.logger.level

      Logster.logger = ::Rails.logger = config.logger = logger
    else
      Rails.logger.warn "Not loading logster, Redis missing"
    end
  end

  def self.initialize!(app)
    return unless Rails.env.development? || Rails.env.production?

    if Logster::Logger === Rails.logger
      if Rails.env.development?
        # in production you must mount in routes.rb
        # or by inserting middleware
        app.middleware.use Logster::Middleware::Viewer
      end

      app.middleware.insert_before ActionDispatch::ShowExceptions, Logster::Middleware::Reporter

      app.config.colorize_logging = false
    end
  end

  class Railtie < ::Rails::Railtie

    config.before_initialize do
      Logster::Rails.set_logger(config)
    end

    initializer "logster.configure_rails_initialization" do |app|
      Logster::Rails.initialize!(app)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
logster-0.0.6 lib/logster/rails/railtie.rb
logster-0.0.5 lib/logster/rails/railtie.rb