Sha256: 57631d190a7fcf291f10ad79aa1224f12de7069fbc9eb4064a1aab435cfbc059
Contents?: true
Size: 1.27 KB
Versions: 2
Compression:
Stored size: 1.27 KB
Contents
# 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 $: << '../src' 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 => '{%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"}
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
log4r-1.1.1 | examples/syslogcustom.rb |
log4r-1.1.0 | examples/syslogcustom.rb |