File: myformatter.rb

package info (click to toggle)
ruby-log4r 1.1.10-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 648 kB
  • sloc: ruby: 2,744; xml: 96; makefile: 5
file content (23 lines) | stat: -rw-r--r-- 651 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# try out a custom formatter

$: << '../lib'

require "log4r"

class MyFormatter <  Log4r::Formatter
  def format(event)
    buff = "The level is #{event.level} and has "
    buff += "name '#{Log4r::LNAMES[event.level]}'\n"
    buff += "The logger is '#{event.name}' "
    buff += "and the data type is #{event.data.class}\n"
    buff += "Let's inspect the data:\n"
    buff += event.data.inspect + "\n"
    buff += "We were called at #{event.tracer[0]}\n\n"
  end
end

log = Log4r::Logger.new('custom formatter')
log.trace = true
log.add Log4r::StdoutOutputter.new('stdout', :formatter=>MyFormatter)
log.info [1, 2, 3, 4]
log.error "A log statement"