Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #8347: logger.rb_add_outputfile.patch

File logger.rb_add_outputfile.patch, 1.0 kB (added by lhartley, 2 years ago)

changes to logger to support output to file or STDERR

  • logger.rb

    old new  
    99     
    1010    MAX_LEVEL = 3 
    1111 
    12     def initialize(options={}) 
    13       output = options[:output] || STDERR 
     12    def initialize() 
     13      setDevice() 
     14      @level = 0 
     15    end 
     16 
     17    def close 
     18      @device.close if @needs_close 
     19    end 
     20 
     21    def setDevice(options={}) 
     22        output = options[:device] || STDERR 
     23        output = STDERR if output = "" 
    1424      case 
    1525        when output.respond_to?(:puts) 
    1626          @device = output 
     
    1828          @device = File.open(output.to_str, "a") 
    1929          @needs_close = true 
    2030      end 
    21  
    22       @options = options 
    23       @level = 0 
     31        @options = options 
    2432    end 
    25  
    26     def close 
    27       @device.close if @needs_close 
    28     end 
    29  
     33       
    3034    def log(level, message, line_prefix=nil) 
    3135      if level <= self.level 
    3236        indent = "%*s" % [MAX_LEVEL, "*" * (MAX_LEVEL - level)]