Class: Logging::Formatters::Default

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

Overview

Default formatter. No colours, just log level, time stamp, label and the actual log message.

Direct Known Subclasses

Colourful, JustMessage

Constant Summary collapse

FORMAT_STRINGS =

Format strings.

The ‘single` key is used by #format_single_message, whereas `header` is used by #format_multiple_messages.

{
  single: '%-5s %s -- %s',
  header: '%-5s %s'
}

Instance Method Summary collapse

Instance Method Details

#format_multiple_messages(level, label, messages, &block) ⇒ String

TODO:

There’s no documentation for the block yet, it’s being used only for extending functionality from the subclasses. It should be probably refactored, otherwise it will get proper documentation.

Format multiple log messages.

See Also:

  • `FORMAT_STRINGS[:header]`


61
62
63
64
65
66
67
68
# File 'lib/logging/formatters.rb', line 61

def format_multiple_messages(level, label, messages, &block)
  args = [level.to_s.upcase, timestamp]
  args = block.call(*args) if block

  header = sprintf(self.class::FORMAT_STRINGS[:header], *args)
  messages.unshift(nil)
  header + messages.join("\n  ")
end

#format_single_message(level, label, message, &block) ⇒ String

TODO:

There’s no documentation for the block yet, it’s being used only for extending functionality from the subclasses. It should be probably refactored, otherwise it will get proper documentation.

Format single log message.

See Also:

  • `FORMAT_STRINGS[:single]`


38
39
40
41
42
# File 'lib/logging/formatters.rb', line 38

def format_single_message(level, label, message, &block)
  args = [label, timestamp, message]
  args = block.call(*args) if block
  sprintf(self.class::FORMAT_STRINGS[:single], *args)
end