Class: Log4r::BasicFormatter

### Home Classes Methods

### In Files

- lib/log4r/formatter/formatter.rb

### Parent

Log4r::SimpleFormatter

### Methods

- ::new
- #format
- #format_object

### Files

- GDC
- MDC
- NDC
- configurator
- emailoutputter
- formatter
- log4jxmlformatter
- log4r
- logger
- logserver
- outputter
- patternformatter
- scribeoutputter
- syslogoutputter
- win32eventoutputter
- yamlconfigurator

### Class/Module Index

Quicksearch

- Log4r
- Log4r::BasicFormatter
- Log4r::ConfigError
- Log4r::Configurator
- Log4r::DateFileOutputter
- Log4r::DefaultFormatter
- Log4r::EmailOutputter
- Log4r::FileOutputter
- Log4r::Formatter
- Log4r::GDC
- Log4r::IOOutputter
- Log4r::Log4jXmlFormatter
- Log4r::Log4rTools
- Log4r::LogEvent
- Log4r::LogServer
- Log4r::Logger
- Log4r::MDC
- Log4r::NDC
- Log4r::ObjectFormatter
- Log4r::Outputter
- Log4r::PatternFormatter
- Log4r::RemoteOutputter
- Log4r::RollingFileOutputter
- Log4r::RootLogger
- Log4r::ScribeOutputter
- Log4r::SimpleFormatter
- Log4r::StderrOutputter
- Log4r::StdoutOutputter
- Log4r::SyslogOutputter
- Log4r::UDPOutputter
- Log4r::YamlConfigurator
- REXML
- Object

No matching classes.

# Log4r::BasicFormatter

BasicFormatter produces output like this:

    WARN loggername: I dropped my Wookie!

Or like this if trace is on:

    WARN loggername(file.rb at 12): Hot potato!

Also, it will pretty-print any Exception it gets and `inspect` everything else.

Hash arguments include:

`depth` | How many lines of the stacktrace to display.

### Public Class Methods

new(hash={}) click to toggle source

    # File lib/log4r/formatter/formatter.rb, line 51
    def initialize(hash={})
      @depth = (hash[:depth] or hash['depth'] or 7).to_i
    end

### Public Instance Methods

format(event) click to toggle source

    # File lib/log4r/formatter/formatter.rb, line 55
    def format(event)
      buff = sprintf(@@basicformat, MaxLevelLength, LNAMES[event.level],
             event.name)
      buff << (event.tracer.nil? ? "" : "(#{event.tracer[0]})") + ": "
      buff << format_object(event.data) + "\n"
      buff
    end

format_object(obj) click to toggle source

Formats data according to its class:

String | Prints it out as normal.
Exception | Produces output similar to command-line exceptions.
Object | Prints the type of object, then the output of `inspect`. An example -- Array: [1, 2, 3]

    # File lib/log4r/formatter/formatter.rb, line 70
    def format_object(obj)
      if obj.kind_of? Exception
        return "Caught #{obj.class}: #{obj.message}\n\t" +                (obj.backtrace.nil? ? [] : obj.backtrace[0...@depth]).join("\n\t")
      elsif obj.kind_of? String
        return obj
      else # inspect the object
        return "#{obj.class}: #{obj.inspect}"
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.