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
51:     def initialize(hash={})
52:       @depth = (hash[:depth] or hash['depth'] or 7).to_i
53:     end

Public Instance Methods

format(event) click to toggle source
    # File lib/log4r/formatter/formatter.rb, line 55
55:     def format(event)
56:       buff = sprintf(@@basicformat, MaxLevelLength, LNAMES[event.level],
57:              event.name)
58:       buff << (event.tracer.nil? ? "" : "(#{event.tracer[0]})") + ": "
59:       buff << format_object(event.data) + "\n"
60:       buff
61:     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
70:     def format_object(obj)
71:       if obj.kind_of? Exception
72:         return "Caught #{obj.class}: #{obj.message}\n\t" +                (obj.backtrace.nil? ? [] : obj.backtrace[0...@depth]).join("\n\t")
73:       elsif obj.kind_of? String
74:         return obj
75:       else # inspect the object
76:         return "#{obj.class}: #{obj.inspect}"
77:       end
78:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.