Sha256: a424627a12829f5c01aab2c60f6741d7a49731089b6cbba0a5b2b282cdd50b06

Contents?: true

Size: 1.31 KB

Versions: 20

Compression:

Stored size: 1.31 KB

Contents

require 'rubygems'
require 'log4r/outputter/outputter'
require 'log4r/formatter/formatter'


module OMF::Web::Widget::Log
  
  class LogOutputter < Log4r::Outputter
    @@instance = nil
    
    def self.instance
      @@instance
    end
    
    def initialize(name = 'remote', hash={})
      puts ">>>> LOG_OUTPUTTER"
      super(name, hash)
      self.formatter = (hash[:formatter] or hash['formatter'] or WebFormatter.new)

      @event = []
      @@instance = self
    end
    
    def remaining_events(index)
      @event[index .. -1]
    end
  
    def format(logevent)
      # @formatter is guaranteed to be DefaultFormatter if no Formatter
      # was specified
      @event << [@formatter.format(logevent), logevent]
      #puts ">>>>>>>>>>>>>>>> #{logevent.inspect}"
    end

  end # LogOutputter
  
  class WebFormatter < Log4r::BasicFormatter

    def format(event)
      lname = Log4r::LNAMES[event.level]
      fs = "<tr class=\"log_#{lname.downcase}\"><td class='%s'>%s</td><td class='name'>%s"
      buff = sprintf(fs, lname.downcase, lname, event.name)
      buff += (event.tracer.nil? ? "" : "(#{event.tracer[0]})") + ":</td>"
      data = format_object(event.data).gsub(/</, '&lt;')
      buff += sprintf("<td class='data'>%*s</td></tr>", Log4r::MaxLevelLength, data)
      buff
    end

  end # WebFormatter

end # module
  

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
omf_web-1.2.9 lib/omf-web/widget/UNUSED/log/log_outputter.rb
omf_web-1.2.8 lib/omf-web/widget/UNUSED/log/log_outputter.rb
omf_web-1.2.7 lib/omf-web/widget/UNUSED/log/log_outputter.rb
omf_web-1.2.6 lib/omf-web/widget/UNUSED/log/log_outputter.rb
omf_web-1.2.5 lib/omf-web/widget/UNUSED/log/log_outputter.rb
omf_web-1.2.4 lib/omf-web/widget/UNUSED/log/log_outputter.rb
omf_web-1.2.3 lib/omf-web/widget/UNUSED/log/log_outputter.rb
omf_web-1.2.2 lib/omf-web/widget/UNUSED/log/log_outputter.rb
omf_web-1.2.1 lib/omf-web/widget/UNUSED/log/log_outputter.rb
omf_web-1.2.0 lib/omf-web/widget/UNUSED/log/log_outputter.rb
omf_web-1.0.0 lib/omf-web/widget/UNUSED/log/log_outputter.rb
omf_web-0.9.9 lib/omf-web/widget/UNUSED/log/log_outputter.rb
omf_web-0.9.8 lib/omf-web/widget/UNUSED/log/log_outputter.rb
omf_web-0.9.7 lib/omf-web/widget/UNUSED/log/log_outputter.rb
omf_web-0.9.6 lib/omf-web/widget/UNUSED/log/log_outputter.rb
omf_web-0.9.5 lib/omf-web/widget/UNUSED/log/log_outputter.rb
omf_web-0.9.4 lib/omf-web/widget/UNUSED/log/log_outputter.rb
omf_web-0.9.3 lib/omf-web/widget/UNUSED/log/log_outputter.rb
omf_web-0.9.1 lib/omf-web/widget/UNUSED/log/log_outputter.rb
omf_web-0.9 lib/omf-web/widget/UNUSED/log/log_outputter.rb