Class: Semlogr::Formatters::PropertyValueFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/semlogr/formatters/property_value_formatter.rb

Constant Summary collapse

QUOTE =
'"'.freeze

Class Method Summary collapse

Class Method Details

.format(output, property_value) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/semlogr/formatters/property_value_formatter.rb', line 6

def self.format(output, property_value)
  case property_value
  when nil
    output << '(nil)'.freeze
  when String
    output << QUOTE
    output << property_value
    output << QUOTE
  when StandardError
    output << "#{property_value.class}: #{property_value.message}"

    if property_value.backtrace
      output << "\n\s\s#{property_value.backtrace.join("\n\s\s")}"
    end

    output << "\n"
  else
    output << property_value.to_s
  end
end