From 0227af92b1851d5eac4cb423dc0c9935dbc733a3 Mon Sep 17 00:00:00 2001 From: Cristian Bica Date: Tue, 20 May 2014 14:41:14 +0300 Subject: Added logging capabilities --- lib/active_job/base.rb | 5 ++++- lib/active_job/enqueuing.rb | 1 + lib/active_job/log_subscriber.rb | 19 +++++++++++++++++++ lib/active_job/logging.rb | 5 +++++ 4 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 lib/active_job/log_subscriber.rb create mode 100644 lib/active_job/logging.rb diff --git a/lib/active_job/base.rb b/lib/active_job/base.rb index 77b929d4af..ed402bd8d3 100644 --- a/lib/active_job/base.rb +++ b/lib/active_job/base.rb @@ -1,11 +1,14 @@ require 'active_job/queue_adapter' require 'active_job/queue_name' require 'active_job/enqueuing' +require 'active_job/logging' +require 'active_job/log_subscriber' module ActiveJob class Base extend QueueAdapter extend QueueName extend Enqueuing + extend Logging end -end \ No newline at end of file +end diff --git a/lib/active_job/enqueuing.rb b/lib/active_job/enqueuing.rb index 324385216e..46f703481a 100644 --- a/lib/active_job/enqueuing.rb +++ b/lib/active_job/enqueuing.rb @@ -11,6 +11,7 @@ module ActiveJob # 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 diff --git a/lib/active_job/log_subscriber.rb b/lib/active_job/log_subscriber.rb new file mode 100644 index 0000000000..81859d8da1 --- /dev/null +++ b/lib/active_job/log_subscriber.rb @@ -0,0 +1,19 @@ +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 diff --git a/lib/active_job/logging.rb b/lib/active_job/logging.rb new file mode 100644 index 0000000000..7bd77b7ca5 --- /dev/null +++ b/lib/active_job/logging.rb @@ -0,0 +1,5 @@ +module ActiveJob + module Logging + mattr_accessor(:logger) { ActiveSupport::Logger.new(STDOUT) } + end +end -- cgit v1.2.3