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
-
#call(severity, time, progname, data) ⇒ String
Override the call method to support hash input/output, and wrap plain strings in a Hash under a
msgkey.
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.
IMPORTANT: This only applies when LogStruct is enabled. When disabled, we preserve the original Rails logging behavior to avoid wrapping messages in hashes (which would break default Rails log formatting).
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/log_struct/monkey_patches/active_support/tagged_logging/formatter.rb', line 35 def call(severity, time, progname, data) # Skip hash wrapping when LogStruct is disabled to preserve default Rails behavior return super unless ::LogStruct.enabled? # 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 = T.unsafe(self).respond_to?(:current_tags) ? : (Thread.current[:activesupport_tagged_logging_tags] || []) data[:tags] = if .present? # Call the original formatter with our enhanced data super end |