Class: JsonLogging::JsonLogger

Inherits:
ActiveSupport::Logger
  • Object
show all
Includes:
JsonLoggerExtension
Defined in:
lib/json_logging/json_logger.rb

Constant Summary

Constants included from JsonLoggerExtension

JsonLogging::JsonLoggerExtension::SEVERITY_NAMES

Instance Method Summary collapse

Methods included from JsonLoggerExtension

#add, #flush, #format_message, #formatter, #formatter=, #tagged

Constructor Details

#initialize(*args, **kwargs) ⇒ JsonLogger

Returns a new instance of JsonLogger.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/json_logging/json_logger.rb', line 9

def initialize(*args, **kwargs)
  # Initialize with minimal args to avoid ActiveSupport::Logger threading issues
  # Rails 7+ supports kwargs, Rails 6 uses positional args only
  logdev = args.first || $stdout
  shift_age = args[1] || 0
  shift_size = args[2]

  # Handle both positional and keyword arguments for Rails 6-8 compatibility
  if kwargs.empty? && shift_size
    super(logdev, shift_age, shift_size)
  elsif kwargs.empty?
    super(logdev, shift_age)
  else
    # Rails 7+ may pass kwargs - delegate to parent
    super
  end

  @formatter_with_tags = FormatterWithTags.new(self)
  # Ensure parent class (Logger) also uses our formatter in case it uses it directly
  instance_variable_set(:@formatter, @formatter_with_tags)
end