Class: Makit::Logging::Formatters::PlainTextFormatter
- Defined in:
- lib/makit/logging/formatters/plain_text_formatter.rb
Overview
Plain text formatter with just the message
Formats log requests as plain text containing only the message content. This is useful for simple log files where only the message matters.
Instance Attribute Summary collapse
-
#include_context ⇒ Boolean
readonly
Whether to include context in output.
Instance Method Summary collapse
-
#config ⇒ Hash
Get formatter configuration.
-
#format(log_request) ⇒ String
Format log request as plain text.
-
#initialize(include_context: false) ⇒ PlainTextFormatter
constructor
Initialize plain text formatter.
Constructor Details
#initialize(include_context: false) ⇒ PlainTextFormatter
Initialize plain text formatter
24 25 26 |
# File 'lib/makit/logging/formatters/plain_text_formatter.rb', line 24 def initialize(include_context: false) @include_context = include_context end |
Instance Attribute Details
#include_context ⇒ Boolean (readonly)
Returns whether to include context in output.
19 20 21 |
# File 'lib/makit/logging/formatters/plain_text_formatter.rb', line 19 def include_context @include_context end |
Instance Method Details
#config ⇒ Hash
Get formatter configuration
63 64 65 66 67 |
# File 'lib/makit/logging/formatters/plain_text_formatter.rb', line 63 def config super.merge( include_context: @include_context, ) end |
#format(log_request) ⇒ String
Format log request as plain text
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/makit/logging/formatters/plain_text_formatter.rb', line 32 def format(log_request) = log_request. # Add context if enabled and present if @include_context && !log_request.context.empty? # Create a more readable context representation context_parts = log_request.context.map do |k, v| # Format values nicely based on their type formatted_value = case v when String v.include?(" ") ? "\"#{v}\"" : v when Hash, Array v.inspect when Time v.strftime("%Y-%m-%d %H:%M:%S") else v.to_s end "#{k}: #{formatted_value}" end context_str = context_parts.join(", ") += " (#{context_str})" end end |