Sha256: f603f9cc6b050cc6c9bb6fa1e6a37c00196da201569d0506cf30953fa6e0bded

Contents?: true

Size: 1.51 KB

Versions: 14

Compression:

Stored size: 1.51 KB

Contents

module GoodJob
  module Logging
    extend ActiveSupport::Concern

    included do
      cattr_accessor :logger, default: ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new(STDOUT))

      def self.tag_logger(*tags)
        if logger.respond_to?(:tagged)
          tags.unshift "GoodJob" unless logger.formatter.current_tags.include?("GoodJob")
          logger.tagged(*tags) { yield }
        else
          yield
        end
      end
    end

    class LogSubscriber < ActiveSupport::LogSubscriber
      def create(event)
        good_job = event.payload[:good_job]

        info do
          "Created GoodJob resource with id #{good_job.id}"
        end
      end

      def timer_task_finished(event)
        exception = event.payload[:error]
        return unless exception

        error do
          "ERROR: #{exception}\n #{exception.backtrace}"
        end
      end

      def job_finished(event)
        exception = event.payload[:error]
        return unless exception

        error do
          "ERROR: #{exception}\n #{exception.backtrace}"
        end
      end

      def scheduler_start_shutdown(_event)
        info do
          "Shutting down scheduler..."
        end
      end

      def scheduler_shutdown(_event)
        info do
          "Scheduler is shut down."
        end
      end

      private

      def logger
        GoodJob.logger
      end

      def thread_name
        Thread.current.name || Thread.current.object_id
      end
    end
  end
end

GoodJob::Logging::LogSubscriber.attach_to :good_job

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
good_job-1.0.3 lib/good_job/logging.rb
good_job-1.0.2 lib/good_job/logging.rb
good_job-1.0.1 lib/good_job/logging.rb
good_job-1.0.0 lib/good_job/logging.rb
good_job-0.9.0 lib/good_job/logging.rb
good_job-0.8.2 lib/good_job/logging.rb
good_job-0.8.1 lib/good_job/logging.rb
good_job-0.8.0 lib/good_job/logging.rb
good_job-0.7.0 lib/good_job/logging.rb
good_job-0.6.0 lib/good_job/logging.rb
good_job-0.5.0 lib/good_job/logging.rb
good_job-0.4.0 lib/good_job/logging.rb
good_job-0.3.0 lib/good_job/logging.rb
good_job-0.2.2 lib/good_job/logging.rb