Class: LogStruct::Integrations::GoodJob::Logger

Inherits:
SemanticLogger::Logger show all
Extended by:
T::Sig
Defined in:
lib/log_struct/integrations/good_job/logger.rb

Overview

Custom Logger for GoodJob that creates LogStruct::Log::GoodJob entries

GoodJob's own messages are logged as Log::GoodJob::Log lines with the process and thread, and, during a job, the job's ID, class, queue, execution count, scheduled time and priority.

Usage:

This logger is automatically configured when the GoodJob integration is enabled. It replaces GoodJob.logger to provide structured logging for all GoodJob operations.

Instance Attribute Summary

Attributes inherited from SemanticLogger::Logger

#broadcasts, #formatter

Class Method Summary collapse

Methods inherited from SemanticLogger::Logger

#<<, #broadcast_to, #clear_tags!, #current_tags, #initialize, #pop_tags, #push_tags, #stop_broadcasting_to, #tagged

Constructor Details

This class inherits a constructor from LogStruct::SemanticLogger::Logger

Class Method Details

.current_job_context ⇒ Hash{Symbol => T.untyped}

The job GoodJob is running on this thread: CurrentThread.job (a GoodJob::Job) in GoodJob 4, CurrentThread.execution in GoodJob 3

Returns:

  • (Hash{Symbol => T.untyped})


53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/log_struct/integrations/good_job/logger.rb', line 53

def self.current_job_context
  return {} unless defined?(::GoodJob::CurrentThread)

  current = ::GoodJob::CurrentThread
  job = (current.job if current.respond_to?(:job)) || (current.execution if current.respond_to?(:execution))
  return {} unless job

  job_class = job.try(:job_class) || job.try(:serialized_params)&.dig("job_class")
  {
    job_id: job.try(:active_job_id)&.to_s,
    job_class: job_class&.to_s,
    queue_name: job.try(:queue_name)&.to_sym,
    executions: job.try(:executions_count) || job.try(:executions),
    scheduled_at: job.try(:scheduled_at),
    priority: job.try(:priority)
  }
end