Sha256: fc989365420389d3db4eeb28e5a4f0b995df261263e7069b9ad7a716b28edacc

Contents?: true

Size: 1.72 KB

Versions: 21

Compression:

Stored size: 1.72 KB

Contents

module Logster::Rails

  # this magically registers logster.js in the asset pipeline
  class Engine < Rails::Engine
  end

  def self.set_logger(config)
    return unless Logster.config.environments.include?(Rails.env.to_sym)

    require 'logster/middleware/debug_exceptions'
    require 'logster/middleware/reporter'

    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
  end


  def self.initialize!(app)
    return unless Logster.config.environments.include?(Rails.env.to_sym)

    if Logster::Logger === Rails.logger
      app.middleware.insert_before ActionDispatch::ShowExceptions, Logster::Middleware::Reporter

      if Rails::VERSION::MAJOR == 3
        app.middleware.insert_before ActionDispatch::DebugExceptions, Logster::Middleware::DebugExceptions
      else
        app.middleware.insert_before ActionDispatch::DebugExceptions, Logster::Middleware::DebugExceptions, Rails.application
      end

      app.middleware.delete ActionDispatch::DebugExceptions
      app.config.colorize_logging = false

      unless Logster.config.application_version
        git_version = `cd #{Rails.root} && git rev-parse --short HEAD 2> /dev/null`
        if git_version.present?
          Logster.config.application_version = git_version.strip
        end
      end
    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

21 entries across 21 versions & 1 rubygems

Version Path
logster-1.3.1 lib/logster/rails/railtie.rb
logster-1.2.11 lib/logster/rails/railtie.rb
logster-1.2.9 lib/logster/rails/railtie.rb
logster-1.2.8 lib/logster/rails/railtie.rb
logster-1.2.7 lib/logster/rails/railtie.rb
logster-1.2.6 lib/logster/rails/railtie.rb
logster-1.2.5 lib/logster/rails/railtie.rb
logster-1.2.4 lib/logster/rails/railtie.rb
logster-1.2.3 lib/logster/rails/railtie.rb
logster-1.2.2 lib/logster/rails/railtie.rb
logster-1.2.1 lib/logster/rails/railtie.rb
logster-1.2.0 lib/logster/rails/railtie.rb
logster-1.1.1 lib/logster/rails/railtie.rb
logster-1.0.1 lib/logster/rails/railtie.rb
logster-1.0.0.3.pre lib/logster/rails/railtie.rb
logster-1.0.0.2.pre lib/logster/rails/railtie.rb
logster-1.0.0.1.pre lib/logster/rails/railtie.rb
logster-1.0.0.0.pre lib/logster/rails/railtie.rb
logster-0.9.9 lib/logster/rails/railtie.rb
logster-0.8.4.8.pre lib/logster/rails/railtie.rb