Sha256: 3424d54d5594c2317f0856dec686ab1132100d24612120a53153201432af88d2
Contents?: true
Size: 1.5 KB
Versions: 11
Compression:
Stored size: 1.5 KB
Contents
require 'lograge' # if this is an error for you, add 'lograge' to your bundle (left out of this gem's gemspec to keep dependencies down) require 'syslog/logger' module Syslog class Logger alias log add end end 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? || 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.logger = Logatron.configuration.logger 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, pid: Process.pid, app_id: Logatron.configuration.app_id, id: Logatron.msg_id } end end end
Version data entries
11 entries across 11 versions & 1 rubygems