Class: RailsSemanticLogger::ActiveJob::LogSubscriber
- Inherits:
-
ActiveSupport::LogSubscriber
- Object
- ActiveSupport::LogSubscriber
- RailsSemanticLogger::ActiveJob::LogSubscriber
- Defined in:
- lib/rails_semantic_logger/active_job/log_subscriber.rb
Defined Under Namespace
Classes: EventFormatter
Instance Method Summary collapse
- #enqueue(event) ⇒ Object
- #enqueue_at(event) ⇒ Object
- #perform(event) ⇒ Object
- #perform_start(event) ⇒ Object
Methods inherited from ActiveSupport::LogSubscriber
Instance Method Details
#enqueue(event) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/rails_semantic_logger/active_job/log_subscriber.rb', line 6 def enqueue(event) ex = event.payload[:exception_object] if ex log_with_formatter level: :error, event: event do |fmt| { message: "Failed enqueuing #{fmt.job_info} (#{ex.class} (#{ex.message})", exception: ex } end elsif event.payload[:aborted] log_with_formatter level: :info, event: event do |fmt| {message: "Failed enqueuing #{fmt.job_info}, a before_enqueue callback halted the enqueuing execution."} end else log_with_formatter event: event do |fmt| {message: "Enqueued #{fmt.job_info}"} end end end |
#enqueue_at(event) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/rails_semantic_logger/active_job/log_subscriber.rb', line 27 def enqueue_at(event) ex = event.payload[:exception_object] if ex log_with_formatter level: :error, event: event do |fmt| { message: "Failed enqueuing #{fmt.job_info} (#{ex.class} (#{ex.message})", exception: ex } end elsif event.payload[:aborted] log_with_formatter level: :info, event: event do |fmt| {message: "Failed enqueuing #{fmt.job_info}, a before_enqueue callback halted the enqueuing execution."} end else log_with_formatter event: event do |fmt| {message: "Enqueued #{fmt.job_info} at #{fmt.scheduled_at}"} end end end |
#perform(event) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/rails_semantic_logger/active_job/log_subscriber.rb', line 54 def perform(event) ex = event.payload[:exception_object] if ex log_with_formatter event: event, log_duration: true, level: :error do |fmt| { message: "Error performing #{fmt.job_info} in #{event.duration.round(2)}ms", exception: ex } end else log_with_formatter event: event, log_duration: true do |fmt| {message: "Performed #{fmt.job_info} in #{event.duration.round(2)}ms"} end end end |
#perform_start(event) ⇒ Object
48 49 50 51 52 |
# File 'lib/rails_semantic_logger/active_job/log_subscriber.rb', line 48 def perform_start(event) log_with_formatter event: event do |fmt| {message: "Performing #{fmt.job_info}"} end end |