Log4r::Log4jXmlFormatter

Public Instance Methods

format(logevent) click to toggle source
    # File lib/log4r/formatter/log4jxmlformatter.rb, line 20
20:     def format(logevent)
21:       logger = logevent.fullname.gsub('::', '.')
22:       timestamp = (Time.now.to_f * 1000).to_i
23:       level = LNAMES[logevent.level]
24:       message = format_object(logevent.data)
25:       exception = message if logevent.data.kind_of? Exception
26:       file, line, method = parse_caller(logevent.tracer[0]) if logevent.tracer
27:       
28:       builder = Builder::XmlMarkup.new
29:       xml = builder.log4j :event, :logger => logger,
30:                                   :timestamp => timestamp,
31:                                   :level => level,
32:                                   :thread => '' do |e|
33:               e.log4j :NDC, NDC.get
34:               e.log4j :message, message
35:               e.log4j :throwable, exception if exception
36:               e.log4j :locationInfo, :class => '',
37:                                      :method => method,
38:                                      :file => file,
39:                                      :line => line
40:               e.log4j :properties do |p|
41:                 MDC.get_context.each do |key, value|
42:                   p.log4j :data, :name => key, :value => value
43:                 end
44:               end
45:             end
46:       xml
47:     end

Private Instance Methods

parse_caller(line) click to toggle source
    # File lib/log4r/formatter/log4jxmlformatter.rb, line 53
53:     def parse_caller(line)
54:       if /^(.+?):(\d+)(?::in `(.*)')?/ =~ line
55:         file = Regexp.last_match[1]
56:         line = Regexp.last_match[2].to_i
57:         method = Regexp.last_match[3]
58:         [file, line, method]
59:       else
60:         []
61:       end
62:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.