Module: ActiveJob::Temporal::Logger

Extended by:
Logger
Included in:
Logger
Defined in:
lib/activejob/temporal/logger.rb

Overview

Note:

SemanticLogger Detection If the configured logger is a SemanticLogger instance, log entries are passed directly as hashes. Otherwise, the module JSON-stringifies the payload before passing it to the configured Ruby Logger instance.

Structured logging for activejob-temporal gem.

This module provides structured JSON logging with event names and typed attributes. It integrates with SemanticLogger if available, otherwise falls back to standard Ruby Logger with JSON formatting.

All log entries include:

  • event: Event name (String or Symbol)

  • timestamp: ISO8601 UTC timestamp

  • Custom attributes (Hash)

Examples:

Basic logging

Logger.info("job.enqueued", job_id: "123", queue: "default")
# => { "event": "job.enqueued", "timestamp": "2025-10-29T12:00:00Z", "job_id": "123", "queue": "default" }

Error logging

Logger.error("job.failed", job_id: "123", error: "NetworkError")

With SemanticLogger

# If the configured logger is SemanticLogger, structured hash is passed directly
Logger.info("workflow.started", workflow_id: "wf-123")
# SemanticLogger formats as structured JSON

Without SemanticLogger

# Falls back to JSON.generate before calling logger.info
Logger.info("workflow.started", workflow_id: "wf-123")
# => '{"event":"workflow.started","timestamp":"2025-10-31T12:00:00Z","workflow_id":"wf-123"}'

Constant Summary collapse

CONTROL_CHARACTER_PATTERN =
/[[:cntrl:]]/

Instance Method Summary collapse

Instance Method Details

#error(event_name, attributes = {}) ⇒ void

This method returns an undefined value.

Logs an event at ERROR level.

Examples:

Logger.error("job.failed", job_id: "123", error_class: "RuntimeError", message: "Boom")

Parameters:

  • event_name (String, Symbol)

    Name of the event

  • attributes (Hash) (defaults to: {})

    Additional structured data

Raises:

  • (ArgumentError)

    if event_name is not a String or Symbol

  • (ArgumentError)

    if attributes is not a Hash

  • (NoMethodError)

    if logger is not configured



104
105
106
# File 'lib/activejob/temporal/logger.rb', line 104

def error(event_name, attributes = {})
  log(:error, event_name, attributes)
end

#info(event_name, attributes = {}) ⇒ void

This method returns an undefined value.

Logs an event at INFO level.

Examples:

Logger.info("job.completed", job_id: "123", duration_ms: 1500)

Parameters:

  • event_name (String, Symbol)

    Name of the event

  • attributes (Hash) (defaults to: {})

    Additional structured data

Raises:

  • (ArgumentError)

    if event_name is not a String or Symbol

  • (ArgumentError)

    if attributes is not a Hash

  • (NoMethodError)

    if logger is not configured



76
77
78
# File 'lib/activejob/temporal/logger.rb', line 76

def info(event_name, attributes = {})
  log(:info, event_name, attributes)
end

#log_event(event_name, attributes = {}) ⇒ void

This method returns an undefined value.

Logs an event at INFO level.

Examples:

Logger.log_event("workflow.started", workflow_id: "wf-123", job_class: "MyJob")

With complex attributes

Logger.log_event("job.completed", {
  job_id: "abc-123",
  duration_ms: 1500,
  result: { success: true, records_processed: 100 }
})

Parameters:

  • event_name (String, Symbol)

    Name of the event (e.g., “job.enqueued”)

  • attributes (Hash) (defaults to: {})

    Additional structured data to include in log entry

Raises:

  • (ArgumentError)

    if event_name is not a String or Symbol

  • (ArgumentError)

    if attributes is not a Hash

  • (NoMethodError)

    if logger is not configured



62
63
64
# File 'lib/activejob/temporal/logger.rb', line 62

def log_event(event_name, attributes = {})
  log(:info, event_name, attributes)
end

#log_to(configured_logger, level, event_name, attributes = {}) ⇒ Object



108
109
110
# File 'lib/activejob/temporal/logger.rb', line 108

def log_to(configured_logger, level, event_name, attributes = {})
  log(level, event_name, attributes, configured_logger: configured_logger)
end

#warn(event_name, attributes = {}) ⇒ void

This method returns an undefined value.

Logs an event at WARN level.

Examples:

Logger.warn("job.retry", job_id: "123", attempt: 2, error: "Timeout")

Parameters:

  • event_name (String, Symbol)

    Name of the event

  • attributes (Hash) (defaults to: {})

    Additional structured data

Raises:

  • (ArgumentError)

    if event_name is not a String or Symbol

  • (ArgumentError)

    if attributes is not a Hash

  • (NoMethodError)

    if logger is not configured



90
91
92
# File 'lib/activejob/temporal/logger.rb', line 90

def warn(event_name, attributes = {})
  log(:warn, event_name, attributes)
end