Sha256: 006feed09972b9b245dc83d56aa4d9dc55d9792efc5155ede0d3126b0b24fac3

Contents?: true

Size: 1.48 KB

Versions: 127

Compression:

Stored size: 1.48 KB

Contents

$: << File.join("..","lib")

# This file demonstrates how inheritence works in log4r
#
require 'rubygems'
require 'log4r'
include Log4r

Logger.global.level = ALL
formatter = PatternFormatter.new(:pattern => "%l - %m - %c")
StdoutOutputter.new('console', :formatter => formatter)


# By default, the root logger is the top ancestor to the
# immediate descendants
# However, any descendants below the top ancestors will
# have the ancestor as their RootLogger, which dictates
# (among other things) the lowest level of log messages
Logger.new('grandparent', FATAL).add('console')
Logger.new('grandparent::parent', DEBUG)
Logger.new('grandparent::parent::child', DEBUG)


def do_logging(log)
  puts "--"
  log.debug "This is debug"
  log.info "This is info"
  log.warn "This is warn"
  log.error "This is error"
  log.fatal "This is fatal"
end

# This logger is configured to log at FATAL, and it does
do_logging Logger['grandparent']

# This logger is configured to log at DEBUG level, but it logs
# at FATAL because grandparent is now the RootLogger for parent
do_logging Logger['grandparent::parent']

# 'child' logger is configured to log at DEBUG level, but it logs
# at FATAL because of grandparent
do_logging Logger['grandparent::parent::child']


Logger['grandparent'].level = DEBUG
# Now that the grandparent's level is set to DEBUG, the child
# will log at that level
do_logging Logger['grandparent::parent::child']

Logger['grandparent'].level = OFF
puts "off?"
do_logging Logger['grandparent::parent::child']

Version data entries

127 entries across 89 versions & 15 rubygems

Version Path
vagrant-unbundled-2.2.19.0 vendor/bundle/ruby/3.0.0/gems/log4r-1.1.10/examples/ancestors.rb
vagrant-unbundled-2.2.18.0 vendor/bundle/ruby/3.0.0/gems/log4r-1.1.10/examples/ancestors.rb
vagrant-unbundled-2.2.16.0 vendor/bundle/ruby/3.0.0/gems/log4r-1.1.10/examples/ancestors.rb
vagrant-unbundled-2.2.16.0 vendor/bundle/ruby/2.7.0/gems/log4r-1.1.10/examples/ancestors.rb
vagrant-unbundled-2.2.14.0 vendor/bundle/ruby/2.7.0/gems/log4r-1.1.10/examples/ancestors.rb
vagrant-unbundled-2.2.10.0 vendor/bundle/ruby/2.7.0/gems/log4r-1.1.10/examples/ancestors.rb
vagrant-unbundled-2.2.9.0 vendor/bundle/ruby/2.7.0/gems/log4r-1.1.10/examples/ancestors.rb
vagrant-unbundled-2.2.8.0 vendor/bundle/ruby/2.7.0/gems/log4r-1.1.10/examples/ancestors.rb
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.6.0/gems/log4r-1.1.10/examples/ancestors.rb
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.4.0/gems/log4r-1.1.10/examples/ancestors.rb
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.7.0/gems/log4r-1.1.10/examples/ancestors.rb
vagrant-unbundled-2.2.6.2 vendor/bundle/ruby/2.6.0/gems/log4r-1.1.10/examples/ancestors.rb
vagrant-unbundled-2.2.6.1 vendor/bundle/ruby/2.6.0/gems/log4r-1.1.10/examples/ancestors.rb
vagrant-unbundled-2.2.6.0 vendor/bundle/ruby/2.6.0/gems/log4r-1.1.10/examples/ancestors.rb
vagrant-unbundled-2.2.5.0 vendor/bundle/ruby/2.6.0/gems/log4r-1.1.10/examples/ancestors.rb
vagrant-unbundled-2.2.5.0 vendor/bundle/ruby/2.5.0/gems/log4r-1.1.10/examples/ancestors.rb
vagrant-unbundled-2.2.4.0 vendor/bundle/ruby/2.5.0/gems/log4r-1.1.10/examples/ancestors.rb
vagrant-unbundled-2.2.4.0 vendor/bundle/ruby/2.6.0/gems/log4r-1.1.10/examples/ancestors.rb
vagrant-unbundled-2.2.3.0 vendor/bundle/ruby/2.5.0/gems/log4r-1.1.10/examples/ancestors.rb
vagrant-unbundled-2.2.2.0 vendor/bundle/ruby/2.5.0/gems/log4r-1.1.10/examples/ancestors.rb