Class: Wright::Logger::Formatter Private

Inherits:
Logger::Formatter
  • Object
show all
Defined in:
lib/wright/logger.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Default formatter for Wright log messages.

Instance Method Summary collapse

Instance Method Details

#call(severity, _time, _progname, message) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method is called by Wright::Logger to format log messages.

Parameters:

  • severity (String)

    the log entry's severity

  • _time (Time)

    the log entry's time stamp (ignored)

  • _progname (String)

    the log entry's program name (ignored)

  • message (String)

    the log message

Returns:

  • (String)

    the formatted log entry


21
22
23
24
25
26
27
28
# File 'lib/wright/logger.rb', line 21

def call(severity, _time, _progname, message)
  log_entry = "#{severity}: #{message}\n"
  if Wright::Config[:log][:colorize]
    colorize(log_entry, severity)
  else
    log_entry
  end
end

#colorize(string, severity) ⇒ String (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

ANSI-Colorizes a log message according to its severity.

Parameters:

  • string (String)

    the log message to be colorized

  • severity (String)

    the severity of the log message

Returns:

  • (String)

    the colorized log message


38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/wright/logger.rb', line 38

def colorize(string, severity)
  case severity
  when 'ERROR', 'FATAL'
    Wright::Util::Color.red(string)
  when 'WARN'
    Wright::Util::Color.yellow(string)
  when 'INFO'
    string
  else
    string
  end
end