Class: Semlogr::Formatters::PropertyValueFormatter

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

Constant Summary collapse

NO_VALUE =
'(nil)'
NEW_LINE =
"\n"

Class Method Summary collapse

Class Method Details

.format(value) ⇒ Object



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

def self.format(value)
  case value
  when nil
    NO_VALUE
  when String
    "\"#{value}\""
  when StandardError
    formatted_error = +"#{value.class}: #{value.message}"

    if value.backtrace&.any?
      formatted_error << "\n\s\s#{value.backtrace.join("\n\s\s")}"
    end

    formatted_error << NEW_LINE
  else
    value.to_s
  end
end