Class: EventLoggerRails::Output
- Inherits:
-
Object
- Object
- EventLoggerRails::Output
- Defined in:
- lib/event_logger_rails/output.rb
Overview
Merges data from application, request, and logger message for structured output
Instance Method Summary collapse
-
#initialize(level:, timestamp:, message:) ⇒ Output
constructor
Initializes the output with the given level, timestamp, and message.
-
#to_hash ⇒ Hash
Converts the output to a hash containing the application, request, and logger details.
-
#to_json(*args) ⇒ String
Converts the output to a JSON string.
Constructor Details
#initialize(level:, timestamp:, message:) ⇒ Output
Initializes the output with the given level, timestamp, and message.
11 12 13 14 15 16 |
# File 'lib/event_logger_rails/output.rb', line 11 def initialize(level:, timestamp:, message:) @current_request = EventLoggerRails::CurrentRequest @level = level = .iso8601(3) = .respond_to?(:to_hash) ? sanitizer.filter(**) : { message: } end |
Instance Method Details
#to_hash ⇒ Hash
Converts the output to a hash containing the application, request, and logger details.
28 29 30 |
# File 'lib/event_logger_rails/output.rb', line 28 def to_hash application_data.merge(**current_request_data, **logger_data) end |
#to_json(*args) ⇒ String
Converts the output to a JSON string.
21 22 23 |
# File 'lib/event_logger_rails/output.rb', line 21 def to_json(*args) JSON.generate(to_hash, *args) end |