Sha256: 580134080648f2dc3ad8105719dfb6f03a52760db4a3b579e665da782e625f1c

Contents?: true

Size: 1.76 KB

Versions: 10

Compression:

Stored size: 1.76 KB

Contents


require 'log4r/outputter/fileoutputter'

module Log4r
  # When daemonizing, the file handler gets closed and we fall over here. 
  # The following monkey patch retries once to open the file and write again
  #
  class FileOutputter
    
    # def initialize(_name, hash={})
      # raise "#{_name}::#{hash.inspect}"
    # end
    
    def write(data)
      #puts ">>> #{data}"
      begin
        @out.print data
        @out.flush
      rescue IOError => ioe # recover from this instead of crash
        # retry once
        unless @retrying
          @retrying = true
          @out = File.new(@filename, (@trunc ? "w" : "a"))
          return write(data)
        end
        Logger.log_internal {"IOError in Outputter '#{@name}'!"}
        Logger.log_internal {ioe}
        close
      rescue NameError => ne
        Logger.log_internal {"Outputter '#{@name}' IO is #{@out.class}!"}
        Logger.log_internal {ne}
        close
      end
      @retrying = false
    end      
  end
end

# module OMF; module Common; end end
# 
# #
# # An extended object class with support for logging
# #
# module OMF::Common
  # module Log4r
#     
    # class DateFileOutputter < ::Log4r::DateFileOutputter
#       
      # def write(data)
        # puts ">>> #{data}"
        # begin
          # @out.print data
          # @out.flush
        # rescue IOError => ioe # recover from this instead of crash
          # Logger.log_internal {"IOError in Outputter '#{@name}'!"}
          # Logger.log_internal {ioe}
          # close
        # rescue NameError => ne
          # Logger.log_internal {"Outputter '#{@name}' IO is #{@out.class}!"}
          # Logger.log_internal {ne}
          # close
        # end
      # end      
    # end
  # end
# end
# 
# puts "REQUIRE #{OMF::Common::Log4r::DateFileOutputter}"

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
omf_web-1.0.0 lib/omf_common/log4r_outputter.rb
omf_web-0.9.9 lib/omf_common/log4r_outputter.rb
omf_web-0.9.8 lib/omf_common/log4r_outputter.rb
omf_web-0.9.7 lib/omf_common/log4r_outputter.rb
omf_web-0.9.6 lib/omf_common/log4r_outputter.rb
omf_web-0.9.5 lib/omf_common/log4r_outputter.rb
omf_web-0.9.4 lib/omf_common/log4r_outputter.rb
omf_web-0.9.3 lib/omf_common/log4r_outputter.rb
omf_web-0.9.1 lib/omf_common/log4r_outputter.rb
omf_web-0.9 lib/omf_common/log4r_outputter.rb