Class: SysLogger::IO
- Inherits:
-
Object
- Object
- SysLogger::IO
- Defined in:
- lib/syslogger/io.rb
Instance Method Summary collapse
- #close ⇒ Object
- #file ⇒ Object
- #flush ⇒ Object
-
#initialize(&file_creator) ⇒ IO
constructor
A new instance of IO.
- #transmit(message) ⇒ Object
- #write(message) ⇒ Object
Constructor Details
#initialize(&file_creator) ⇒ IO
Returns a new instance of IO.
3 4 5 6 7 |
# File 'lib/syslogger/io.rb', line 3 def initialize(&file_creator) @file_creator = file_creator @file = nil @connect_pid = Process.pid end |
Instance Method Details
#close ⇒ Object
49 50 51 52 53 54 |
# File 'lib/syslogger/io.rb', line 49 def close if !@file.nil? @file.close @file = nil end end |
#file ⇒ Object
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/syslogger/io.rb', line 9 def file # re-connect on fork if Process.pid != @connect_pid @file.close end if @file.nil? || @file.closed? @file = @file_creator.call end @file end |
#flush ⇒ Object
43 44 45 46 47 |
# File 'lib/syslogger/io.rb', line 43 def flush if !@file.nil? @file.flush end end |
#transmit(message) ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/syslogger/io.rb', line 32 def transmit() # UNIXSocket overwrites Object#send, so using file.respond_to?(:send) # does not work. If send and __send__ have different signigutres call # send. Otherwise, call write. unless file.method(:send).hash == file.method(:__send__).hash file.send(, 0) else file.write() end end |
#write(message) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/syslogger/io.rb', line 20 def write() tries = 2 Array().each do |msg| begin transmit(msg) rescue file.close retry unless (tries -= 1).zero? end end end |