Sha256: b4985ab108ff95931b24c7c2978e9f008fde113100c55abf68fb302d609bfbf1

Contents?: true

Size: 1.2 KB

Versions: 2

Compression:

Stored size: 1.2 KB

Contents

module Logatron
  class Middleware
    def initialize(app)
      @app = app
    end
    def call(env)
      request = ActionDispatch::Request.new(env)
      if request.headers['X-Ascent-Log-Id']
        Logatron.msg_id = request.headers['X-Ascent-Log-Id']
      elsif env['rack.session'].nil? or env['rack.session']['warden.user.user.key'].nil?
        Logatron.msg_id = SecureRandom.uuid + '-id-anonymous'
      else
        Logatron.msg_id = SecureRandom.uuid + '-id-' + env['rack.session']['warden.user.user.key'][0][0].to_s
      end
      @app.call(env)
    end
  end

  class Railtie < Rails::Railtie

    initializer 'logatron.configure_rails_initialization' do |app|

      if defined?(Warden::Manager)
        app.middleware.insert_before(Warden::Manager, Logatron::Middleware)
      else
        app.middleware.use Logatron::Middleware
      end

    end


      config.lograge.enabled = true
      config.lograge.formatter = Lograge::Formatters::Json.new
      config.lograge.custom_options = lambda do |event|
        {:source => event.payload[:ip], :severity=> Logatron::INFO, :site => Logatron.site, :timestamp => Time.now.iso8601, :host => Logatron.configuration.host, :id => Logatron.msg_id}
      end

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
logatron-0.1.2 lib/logatron/railtie.rb
logatron-0.1.1 lib/logatron/railtie.rb