Sha256: e1ec722e62025e9f130cb377d951e670d6dbac7b055d137a992e4796e4a765b6

Contents?: true

Size: 1019 Bytes

Versions: 21

Compression:

Stored size: 1019 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' && ZuoraConnect.configuration.json_logging
        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

21 entries across 21 versions & 1 rubygems

Version Path
zuora_connect-2.0.5y lib/resque/plugins/custom_logger.rb