1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
# Suppose we don't like having 5 levels named DEBUG, INFO, etc.
# Suppose we'd rather use 3 levels named Foo, Bar, and Baz.
# Log4r allows you to rename the levels and their corresponding methods
# in a painless way. This file provides and example
$: << '../lib'
require 'log4r'
require 'log4r/configurator'
include Log4r
# This is how we specify our levels
Configurator.custom_levels "Foo", "Bar", "Baz"
l = Logger.new('custom levels')
l.add StdoutOutputter.new('console')
l.level = Foo
puts l.foo?
l.foo "This is foo"
puts l.bar?
l.bar "this is bar"
puts l.baz?
l.baz "this is baz"
puts "Now change to Baz"
l.level = Baz
puts l.foo?
l.foo {"This is foo"}
puts l.bar?
l.bar {"this is bar"}
puts l.baz?
l.baz {"this is baz"}
|