Module: ActiveSupport::TaggedLogging::FormatterExtension

Extended by:
T::Helpers, T::Sig
Defined in:
lib/log_struct/monkey_patches/active_support/tagged_logging/formatter.rb

Instance Method Summary collapse

Instance Method Details

#call(severity, time, progname, data) ⇒ String

Override the call method to support hash input/output, and wrap plain strings in a Hash under a msg key. The data is then passed to our custom log formatter that transforms it into a JSON string before logging.

Parameters:

  • severity (String, Symbol)
  • time (Time)
  • progname (T.untyped)
  • data (T.untyped)

Returns:

  • (String)


31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/log_struct/monkey_patches/active_support/tagged_logging/formatter.rb', line 31

def call(severity, time, progname, data)
  # Convert data to a hash if it's not already one
  data = {message: data.to_s} unless data.is_a?(Hash)

  # Add current tags to the hash if present
  # Use thread-local storage directly as fallback if current_tags method doesn't exist
  tags = T.unsafe(self).respond_to?(:current_tags) ? current_tags : (Thread.current[:activesupport_tagged_logging_tags] || [])
  data[:tags] = tags if tags.present?

  # Call the original formatter with our enhanced data
  super
end