Skip to content

Commit

Permalink
Merge pull request #46 from cristianbica/logging
Browse files Browse the repository at this point in the history
Added logging capabilities
  • Loading branch information
dhh committed May 20, 2014
2 parents 2d19c71 + a265011 commit a8cfb3d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/active_job/base.rb
@@ -1,11 +1,13 @@
require 'active_job/queue_adapter'
require 'active_job/queue_name'
require 'active_job/enqueuing'
require 'active_job/logging'

module ActiveJob
class Base
extend QueueAdapter
extend QueueName
extend Enqueuing
extend Logging
end
end
end
1 change: 1 addition & 0 deletions lib/active_job/enqueuing.rb
Expand Up @@ -11,6 +11,7 @@ module Enqueuing
# The return value is adapter-specific and may change in a future
# ActiveJob release.
def enqueue(*args)
ActiveSupport::Notifications.instrument "enqueue.active_job", adapter: queue_adapter, job: self, params: args
queue_adapter.queue self, *Parameters.serialize(args)
end
end
Expand Down
18 changes: 18 additions & 0 deletions lib/active_job/log_subscriber.rb
@@ -0,0 +1,18 @@
module ActiveJob
class LogSubscriber < ActiveSupport::LogSubscriber
def enqueue(event)
payload = event.payload
params = payload[:params]
adapter = payload[:adapter]
job = payload[:job]

info "ActiveJob enqueued to #{adapter.name.demodulize} job #{job.name}: #{params.inspect}"
end

def logger
ActiveJob::Base.logger
end
end
end

ActiveJob::LogSubscriber.attach_to :active_job
7 changes: 7 additions & 0 deletions lib/active_job/logging.rb
@@ -0,0 +1,7 @@
require 'active_job/log_subscriber'

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

0 comments on commit a8cfb3d

Please sign in to comment.