Class: Lumberjack::Formatter::PrettyPrintFormatter
- Inherits:
-
Object
- Object
- Lumberjack::Formatter::PrettyPrintFormatter
- Defined in:
- lib/lumberjack/formatter/pretty_print_formatter.rb
Overview
Format an object with its pretty print method. This formatter provides multi-line, indented output that makes complex data structures easier to read and debug. It's particularly useful for logging hashes, arrays, and other nested objects.
The formatter uses Ruby's built-in PP (Pretty Print) library to generate well-formatted output with appropriate indentation and line breaks.
Instance Attribute Summary collapse
-
#width ⇒ Integer
The maximum width of the message.
Instance Method Summary collapse
-
#call(obj) ⇒ String
Format an object using pretty print with the configured width.
-
#initialize(width = 79) ⇒ PrettyPrintFormatter
constructor
Create a new formatter.
Constructor Details
#initialize(width = 79) ⇒ PrettyPrintFormatter
Create a new formatter. The maximum width of the message can be specified with the width parameter (defaults to 79 characters).
25 26 27 |
# File 'lib/lumberjack/formatter/pretty_print_formatter.rb', line 25 def initialize(width = 79) @width = width end |
Instance Attribute Details
#width ⇒ Integer
Returns The maximum width of the message.
19 20 21 |
# File 'lib/lumberjack/formatter/pretty_print_formatter.rb', line 19 def width @width end |
Instance Method Details
#call(obj) ⇒ String
Format an object using pretty print with the configured width.
33 34 35 36 37 |
# File 'lib/lumberjack/formatter/pretty_print_formatter.rb', line 33 def call(obj) s = StringIO.new PP.pp(obj, s) s.string.chomp end |