Class Log4r::PatternFormatter
In: lib/log4r/formatter/patternformatter.rb
Parent: BasicFormatter

See log4r/formatter/patternformatter.rb

Methods

new  

Constants

DirectiveTable = { "c" => 'event.name', "C" => 'event.fullname', "d" => 'format_date', "g" => 'Log4r::GDC.get()', "t" => '(event.tracer.nil? ? "no trace" : event.tracer[0])', "T" => '(event.tracer.nil? ? "no trace" : event.tracer[0].split(File::SEPARATOR)[-1])', "m" => 'event.data', "h" => '(Thread.current[:name] or Thread.current.to_s)', "p" => 'Process.pid.to_s', "M" => 'format_object(event.data)', "l" => 'LNAMES[event.level]', "x" => 'Log4r::NDC.get()', "X" => 'Log4r::MDC.get("DTR_REPLACE")', "%" => '"%"'   Arguments to sprintf keyed to directive letters<br> %c - event short name<br> %C - event fullname<br> %d - date<br> %g - Global Diagnostic Context (GDC)<br> %t - trace<br> %m - message<br> %h - thread name<br> %p - process ID aka PID<br> %M - formatted message<br> %l - Level in string form<br> %x - Nested Diagnostic Context (NDC)<br> %X - Mapped Diagnostic Context (MDC), syntax is "%X{key}"<br> %% - Insert a %<br>
DirectiveRegexp = /([^%]*)((%-?\d*(\.\d+)?)([cCdgtTmhpMlxX%]))?(\{.+?\})?(.*)/   Matches the first directive encountered and the stuff around it.
  • $1 is the stuff before directive or "" if not applicable
  • $2 is the directive group or nil if there‘s none
  • $3 is the %#.# match within directive group
  • $4 is the .# match which we don‘t use (it‘s there to match properly)
  • $5 is the directive letter
  • $6 is the stuff after the directive or "" if not applicable
  • $7 is the remainder
ISO8601 = "%Y-%m-%d %H:%M:%S"   default date format

Attributes

date_method  [R] 
date_pattern  [R] 
pattern  [R] 

Public Class methods

Accepts the following hash arguments (either a string or a symbol):

pattern
A pattern format string.
date_pattern
A Time#strftime format string. See the Ruby Time class for details.
date_method
As an option to date_pattern, specify which Time.now method to call. For example, usec or to_s. Specify it as a String or Symbol.

The default date format is ISO8601, which looks like this:

  yyyy-mm-dd hh:mm:ss    =>    2001-01-12 13:15:50

[Validate]