class Log4r::BasicFormatter

BasicFormatter produces output like this:

WARN loggername: I dropped my Wookie!

Or like this if trace is on:

WARN loggername(file.rb at 12): Hot potato!

Also, it will pretty-print any Exception it gets and inspect everything else.

Hash arguments include:

depth

How many lines of the stacktrace to display.

Public Class Methods

new(hash={}) click to toggle source
# File lib/log4r/formatter/formatter.rb, line 51
def initialize(hash={})
  @depth = (hash[:depth] or hash['depth'] or 7).to_i
end

Public Instance Methods

format(event) click to toggle source
# File lib/log4r/formatter/formatter.rb, line 55
def format(event)
  buff = sprintf(@@basicformat, MaxLevelLength, LNAMES[event.level],
         event.name)
  buff << (event.tracer.nil? ? "" : "(#{event.tracer[0]})") + ": "
  buff << format_object(event.data) + "\n"
  buff
end
format_object(obj) click to toggle source

Formats data according to its class:

String

Prints it out as normal.

Exception

Produces output similar to command-line exceptions.

Object

Prints the type of object, then the output of inspect. An example – Array: [1, 2, 3]

# File lib/log4r/formatter/formatter.rb, line 70
def format_object(obj)
  if obj.kind_of? Exception
    return "Caught #{obj.class}: #{obj.message}\n\t" +\
           (obj.backtrace.nil? ? [] : obj.backtrace[0...@depth]).join("\n\t")
  elsif obj.kind_of? String
    return obj
  else # inspect the object
    return "#{obj.class}: #{obj.inspect}"
  end
end