Class: Log4r::FileOutputter

Inherits:
Object
  • Object
show all
Defined in:
lib/omf_common/log4r_outputter.rb

Overview

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

Instance Method Summary collapse

Instance Method Details

#write(data) ⇒ Object

end



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/omf_common/log4r_outputter.rb', line 15

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