Sha256: 01674255d38e04ae8ecb71c21200f45f9b9d83d2485730fe0fcf265952fb93f1

Contents?: true

Size: 976 Bytes

Versions: 54

Compression:

Stored size: 976 Bytes

Contents

# This Resque extension changes the resque default logger to monologger
# and formats the log in json format.
# 
# Monologger supports printing logs in trap block.
# 
module Resque
  module Plugins
    module CustomLogger
      def before_perform(*args)
        Rails.logger.with_fields = { trace_id: SecureRandom.uuid, name: "RailsWorker"} if Rails.logger.class.to_s == 'Ougai::Logger'
        case args.class.to_s
        when "Array"
          if args.first.class == Hash
            data = args.first.merge({:worker_class => self.to_s})
          else
            data = {:worker_class => self.to_s, :args => args}
          end
        when "Hash"
          data = args.merge({:worker_class => self.to_s})
        end
        data = {:msg => 'Starting job', :job => data}
        data.merge!({:app_instance_id => data.dig(:job, 'app_instance_id')}) if data.dig(:job, 'app_instance_id').present?
        Rails.logger.info(data) if data.present?
      end
    end
  end
end

Version data entries

54 entries across 54 versions & 1 rubygems

Version Path
zuora_connect-2.0.5x lib/resque/plugins/custom_logger.rb
zuora_connect-2.0.5w lib/resque/plugins/custom_logger.rb
zuora_connect-2.0.5v lib/resque/plugins/custom_logger.rb
zuora_connect-2.0.5u lib/resque/plugins/custom_logger.rb
zuora_connect-2.0.5t lib/resque/plugins/custom_logger.rb
zuora_connect-2.0.5s lib/resque/plugins/custom_logger.rb
zuora_connect-2.0.5r lib/resque/plugins/custom_logger.rb
zuora_connect-2.0.5q lib/resque/plugins/custom_logger.rb
zuora_connect-2.0.5p lib/resque/plugins/custom_logger.rb
zuora_connect-2.0.5o lib/resque/plugins/custom_logger.rb
zuora_connect-2.0.5n lib/resque/plugins/custom_logger.rb
zuora_connect-2.0.5m lib/resque/plugins/custom_logger.rb
zuora_connect-2.0.5l lib/resque/plugins/custom_logger.rb
zuora_connect-2.0.5k lib/resque/plugins/custom_logger.rb
zuora_connect-2.0.5j lib/resque/plugins/custom_logger.rb
zuora_connect-2.0.5i lib/resque/plugins/custom_logger.rb
zuora_connect-2.0.5h lib/resque/plugins/custom_logger.rb
zuora_connect-2.0.5f lib/resque/plugins/custom_logger.rb
zuora_connect-2.0.5e lib/resque/plugins/custom_logger.rb
zuora_connect-2.0.5d lib/resque/plugins/custom_logger.rb