Method: Logging::Layouts::Pattern::FormatMethodBuilder#handle_level

Defined in:
lib/logging/layouts/pattern.rb

#handle_level(format, directive, precision) ⇒ Object

Add the log event level to the ‘format_string` and the `sprintf_args`. The color scheme is taken into account when formatting the log event level.

format - format String directive - the directive character (‘l’) precision - added back to the format string

Returns nil



483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
# File 'lib/logging/layouts/pattern.rb', line 483

def handle_level( format, directive, precision )
  if colorize_levels?
    name_map = ::Logging::LNAMES.map { |name| color_scheme.color(("#{format}s" % name), name) }
    var = "@name_map_#{name_map_count}"
    layout.instance_variable_set(var.to_sym, name_map)
    self.name_map_count += 1

    format_string << '%s'
    format_string << "{#{precision}}" if precision
    sprintf_args << "#{var}[event.level]"
  else
    format_string << format + 's'
    format_string << "{#{precision}}" if precision
    sprintf_args << DIRECTIVE_TABLE[directive]
  end

  nil
end