lib/logstasher/active_job/log_subscriber.rb in logstasher-2.1.1 vs lib/logstasher/active_job/log_subscriber.rb in logstasher-2.1.2
- old
+ new
@@ -1,20 +1,21 @@
+# frozen_string_literal: true
+
# For Rails 6.0 or below, require the logging module which contains LogSubscriber
-if ActiveJob::VERSION::MAJOR < 6 || (ActiveJob::VERSION::MAJOR == 6 && ActiveJob::VERSION::MINOR == 0)
- require 'active_job/logging'
+if ActiveJob::VERSION::MAJOR < 6 || (ActiveJob::VERSION::MAJOR == 6 && ActiveJob::VERSION::MINOR.zero?)
+ require 'active_job/logging'
else
require 'active_job/log_subscriber'
end
module LogStasher
module ActiveJob
-
BASE_SUBSCRIBER = if defined?(::ActiveJob::LogSubscriber)
- ::ActiveJob::LogSubscriber
- else
- ::ActiveJob::Logging::LogSubscriber
- end
+ ::ActiveJob::LogSubscriber
+ else
+ ::ActiveJob::Logging::LogSubscriber
+ end
class LogSubscriber < BASE_SUBSCRIBER
def enqueue(event)
process_event(event, 'enqueue')
end
@@ -59,11 +60,11 @@
data.merge! extract_duration(event) if type == 'perform'
data.merge! request_context
tags = ['job', type]
tags.push('exception') if data[:exception]
- logger << LogStasher.build_logstash_event(data, tags).to_json + "\n"
+ logger << "#{LogStasher.build_logstash_event(data, tags).to_json}\n"
end
def extract_metadata(event)
{
job_id: event.payload[:job].job_id,
@@ -89,11 +90,10 @@
LogStasher.request_context
end
# The default args_info makes a string. We need objects to turn into JSON.
def args_info(job)
- job.arguments.map { |arg| arg.try(:to_global_id).try(:to_s) || arg }
+ ::ActiveJob::Arguments.serialize(job.arguments)
end
end
end
end
-