aboutsummaryrefslogblamecommitdiffstats
path: root/lib/active_job/logging.rb
blob: 5e33e0da1f73f58ddd8629e0ec8cb4f858e9f264 (plain) (tree)
1
2
3
4
5
                                                
 


                                                                 






















                                                                                                                              

     

                                                       
require 'active_support/core_ext/string/filters'

module ActiveJob
  module Logging
    mattr_accessor(:logger) { ActiveSupport::Logger.new(STDOUT) }

    class LogSubscriber < ActiveSupport::LogSubscriber
      def enqueue(event)
        info "Enqueued #{event.payload[:job].name} to #{queue_name(event)}" + args_info(event)
      end

      def enqueue_at(event)
        info "Enqueued #{event.payload[:job].name} to #{queue_name(event)} at #{event.payload[:timestamp]}" + args_info(event)
      end

      private
        def queue_name(event)
          event.payload[:adapter].name.demodulize.remove('Adapter')
        end

        def args_info(event)
          event.payload[:args].any? ? ": #{event.payload[:args].inspect}" : ""
        end

        def logger
          ActiveJob::Base.logger
        end
    end
  end
end

ActiveJob::Logging::LogSubscriber.attach_to :active_job