Class: Lumberjack::Formatter::PrettyPrintFormatter

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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).

Parameters:

  • width (Integer) (defaults to: 79)

    The maximum width of the message.



25
26
27
# File 'lib/lumberjack/formatter/pretty_print_formatter.rb', line 25

def initialize(width = 79)
  @width = width
end

Instance Attribute Details

#widthInteger

Returns The maximum width of the message.

Returns:

  • (Integer)

    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.

Parameters:

  • obj (Object)

    The object to format.

Returns:

  • (String)

    The pretty-printed representation of the object.



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