/usr/share/doc/ruby-log4r/examples/syslogcustom.rb is in ruby-log4r 1.1.10-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | # Suppose we don't like having 5 levels named DEBUG, INFO, etc.
# Suppose we'd rather use 3 levels named Foo, Bar, and Baz.
# Suppose we'd like to use these with syslog
# Log4r allows you to rename the levels and their corresponding methods
# in a painless way and then map those to corrisponding syslog levels
# or have them all default to LOG_INFO
# This file provides an example
$: << '../lib'
require 'log4r'
require 'log4r/configurator'
require 'log4r/formatter/patternformatter'
require 'log4r/outputter/syslogoutputter'
require 'syslog'
include Log4r
include Syslog::Constants
# This is how we specify our levels
Configurator.custom_levels "Foo", "Bar", "Baz"
l = Logger.new('custom levels')
slp = PatternFormatter.new( :pattern => '{%p} {%h} {%d} {%l} {%C} {%m}', :date_method => 'usec' )
sl = SyslogOutputter.new( 'sysloggertest',
{ :logopt => LOG_CONS | LOG_PID | LOG_PERROR,
:facility => LOG_LOCAL7,
:formatter => slp } )
sl.map_levels_by_name_to_syslog( { "Foo" => "DEBUG", "Bar" => "INFO", "Baz" => "ALERT" } )
l.add sl
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"}
l4r = Logger.new('log4r')
l4r.add Log4r::Outputter.stderr
Log4r::SyslogOutputter.new 'test'
|