class Fig::Log4r::Outputter
Public Class Methods
new(name, file_handle, hash = {})
click to toggle source
Calls superclass method
# File lib/fig/log4r/outputter.rb, line 14 def initialize(name, file_handle, hash = {}) @colors = hash.delete(:colors) @colors ||= { :debug => :white, :info => :light_white, :warn => :yellow, :error => :red, :fatal => {:color => :light_yellow, :background => :red} } @colorize = file_handle.tty? && Fig::OperatingSystem.unix? super(name, file_handle, hash) initialize_colors_by_level() end
Private Instance Methods
canonical_log(logevent)
click to toggle source
# File lib/fig/log4r/outputter.rb, line 48 def canonical_log(logevent) synch { write( format(logevent), logevent ) } end
emit_colorizable(formatted_data, raw_data)
click to toggle source
# File lib/fig/log4r/outputter.rb, line 84 def emit_colorizable(formatted_data, raw_data) color = {} if raw_data.foreground color[:color] = raw_data.foreground end if raw_data.background color[:background] = raw_data.background end @out.print formatted_data.colorize(color) @out.print ''.uncolorize return end
initialize_colors_by_level()
click to toggle source
# File lib/fig/log4r/outputter.rb, line 32 def initialize_colors_by_level() @colors_by_level = {} Log4r::LNAMES.each_index do |index| name_symbol = Log4r::LNAMES[index].downcase.to_sym color = @colors[name_symbol] if color @colors_by_level[index] = color end end return end
write(data, logevent)
click to toggle source
# File lib/fig/log4r/outputter.rb, line 52 def write(data, logevent) begin if not @colorize @out.print data else if logevent.data.is_a? Fig::Logging::Colorizable emit_colorizable(data, logevent.data) else color = @colors_by_level[logevent.level] if color @out.print data.colorize(color) @out.print ''.uncolorize else @out.print data end end end @out.flush rescue IOError => error # recover from this instead of crash Log4r::Logger.log_internal {"IOError in Outputter '#{@name}'!"} Log4r::Logger.log_internal {error} close rescue NameError => error Log4r::Logger.log_internal {"Outputter '#{@name}' IO is #{@out.class}!"} Log4r::Logger.log_internal {error} close end return end