File: customlevels.rb

package info (click to toggle)
ruby-log4r 1.1.10-4.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid, trixie
  • size: 648 kB
  • sloc: ruby: 2,744; xml: 96; makefile: 5
file content (34 lines) | stat: -rw-r--r-- 732 bytes parent folder | download | duplicates (3)
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"}