Method: Logging::Layouts::Pattern::FormatMethodBuilder#handle_logger
- Defined in:
- lib/logging/layouts/pattern.rb
#handle_logger(format, directive, slice) ⇒ Object
Add the logger name to the format_string and the sprintf_args. The slice argument is a little interesting - this is the number of logger name segments to keep. If we have a logger named “Foo::Bar::Baz” and our slice is 2, then “Bar::Baz” will appear in the generated log message. So the slice selects the last two parts of the logger name.
format - format String directive - the directive character (‘c’) slice - the number of name segments to keep
Returns nil
452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 |
# File 'lib/logging/layouts/pattern.rb', line 452 def handle_logger( format, directive, slice ) fmt = format + 's' fmt = color_scheme.color(fmt, COLOR_ALIAS_TABLE[directive]) if colorize? format_string << fmt sprintf_args << DIRECTIVE_TABLE[directive].dup if slice numeric = Integer(slice) rescue nil if numeric raise ArgumentError, "logger name slice must be an integer greater than zero: #{numeric}" unless numeric > 0 sprintf_args.last << ".split(::Logging::Repository::PATH_DELIMITER)" \ ".last(#{slice}).join(::Logging::Repository::PATH_DELIMITER)" else format_string << "{#{slice}}" end end nil end |