Sha256: 6124b5436d8770c91bc6e357c97003a5ce8b27309adc6208ecd64e6423b7e4cf

Contents?: true

Size: 651 Bytes

Versions: 127

Compression:

Stored size: 651 Bytes

Contents

# try out a custom formatter

$: << '../lib'

require "log4r"

class MyFormatter <  Log4r::Formatter
  def format(event)
    buff = "The level is #{event.level} and has "
    buff += "name '#{Log4r::LNAMES[event.level]}'\n"
    buff += "The logger is '#{event.name}' "
    buff += "and the data type is #{event.data.class}\n"
    buff += "Let's inspect the data:\n"
    buff += event.data.inspect + "\n"
    buff += "We were called at #{event.tracer[0]}\n\n"
  end
end

log = Log4r::Logger.new('custom formatter')
log.trace = true
log.add Log4r::StdoutOutputter.new('stdout', :formatter=>MyFormatter)
log.info [1, 2, 3, 4]
log.error "A log statement"

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/myformatter.rb
vagrant-unbundled-2.2.18.0 vendor/bundle/ruby/3.0.0/gems/log4r-1.1.10/examples/myformatter.rb
vagrant-unbundled-2.2.16.0 vendor/bundle/ruby/3.0.0/gems/log4r-1.1.10/examples/myformatter.rb
vagrant-unbundled-2.2.16.0 vendor/bundle/ruby/2.7.0/gems/log4r-1.1.10/examples/myformatter.rb
vagrant-unbundled-2.2.14.0 vendor/bundle/ruby/2.7.0/gems/log4r-1.1.10/examples/myformatter.rb
vagrant-unbundled-2.2.10.0 vendor/bundle/ruby/2.7.0/gems/log4r-1.1.10/examples/myformatter.rb
vagrant-unbundled-2.2.9.0 vendor/bundle/ruby/2.7.0/gems/log4r-1.1.10/examples/myformatter.rb
vagrant-unbundled-2.2.8.0 vendor/bundle/ruby/2.7.0/gems/log4r-1.1.10/examples/myformatter.rb
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.6.0/gems/log4r-1.1.10/examples/myformatter.rb
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.4.0/gems/log4r-1.1.10/examples/myformatter.rb
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.7.0/gems/log4r-1.1.10/examples/myformatter.rb
vagrant-unbundled-2.2.6.2 vendor/bundle/ruby/2.6.0/gems/log4r-1.1.10/examples/myformatter.rb
vagrant-unbundled-2.2.6.1 vendor/bundle/ruby/2.6.0/gems/log4r-1.1.10/examples/myformatter.rb
vagrant-unbundled-2.2.6.0 vendor/bundle/ruby/2.6.0/gems/log4r-1.1.10/examples/myformatter.rb
vagrant-unbundled-2.2.5.0 vendor/bundle/ruby/2.6.0/gems/log4r-1.1.10/examples/myformatter.rb
vagrant-unbundled-2.2.5.0 vendor/bundle/ruby/2.5.0/gems/log4r-1.1.10/examples/myformatter.rb
vagrant-unbundled-2.2.4.0 vendor/bundle/ruby/2.5.0/gems/log4r-1.1.10/examples/myformatter.rb
vagrant-unbundled-2.2.4.0 vendor/bundle/ruby/2.6.0/gems/log4r-1.1.10/examples/myformatter.rb
vagrant-unbundled-2.2.3.0 vendor/bundle/ruby/2.5.0/gems/log4r-1.1.10/examples/myformatter.rb
vagrant-unbundled-2.2.2.0 vendor/bundle/ruby/2.5.0/gems/log4r-1.1.10/examples/myformatter.rb