Class: Log4r::Log4jXmlFormatter

### Home Classes Methods

### In Files

- lib/log4r/formatter/log4jxmlformatter.rb

### Parent

Log4r::BasicFormatter

### Methods

- #format

### 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::Log4jXmlFormatter

### Public Instance Methods

format(logevent) click to toggle source

    # File lib/log4r/formatter/log4jxmlformatter.rb, line 20
    def format(logevent)
      logger = logevent.fullname.gsub('::', '.')
      timestamp = (Time.now.to_f * 1000).to_i
      level = LNAMES[logevent.level]
      message = format_object(logevent.data)
      exception = message if logevent.data.kind_of? Exception
      file, line, method = parse_caller(logevent.tracer[0]) if logevent.tracer

      builder = Builder::XmlMarkup.new
      xml = builder.log4j :event, :logger => logger,
                                  :timestamp => timestamp,
                                  :level => level,
                                  :thread => '' do |e|
              e.log4j :NDC, NDC.get
              e.log4j :message, message
              e.log4j :throwable, exception if exception
              e.log4j :locationInfo, :class => '',
                                     :method => method,
                                     :file => file,
                                     :line => line
              e.log4j :properties do |p|
                MDC.get_context.each do |key, value|
                  p.log4j :data, :name => key, :value => value
                end
              end
            end
      xml
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.