Class: PerfectQueue::DaemonsLogger
- Inherits:
-
Logger
- Object
- Logger
- PerfectQueue::DaemonsLogger
- Defined in:
- lib/perfectqueue/daemons_logger.rb
Instance Method Summary collapse
- #close ⇒ Object
- #hook_stderr! ⇒ Object
- #hook_stdout! ⇒ Object
-
#initialize(dev, shift_age = 0, shift_size = 1048576) ⇒ DaemonsLogger
constructor
A new instance of DaemonsLogger.
- #reopen ⇒ Object
- #reopen! ⇒ Object
Constructor Details
#initialize(dev, shift_age = 0, shift_size = 1048576) ⇒ DaemonsLogger
Returns a new instance of DaemonsLogger.
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/perfectqueue/daemons_logger.rb', line 22 def initialize(dev, shift_age=0, shift_size=1048576) @stdout_hook = false @stderr_hook = false if dev.is_a?(String) @path = dev @io = File.open(@path, File::WRONLY|File::APPEND|File::CREAT) else @io = dev end super(@io, shift_size, shift_size) end |
Instance Method Details
#close ⇒ Object
70 71 72 73 74 75 |
# File 'lib/perfectqueue/daemons_logger.rb', line 70 def close if @path @io.close unless @io.closed? end nil end |
#hook_stderr! ⇒ Object
41 42 43 44 45 |
# File 'lib/perfectqueue/daemons_logger.rb', line 41 def hook_stderr! STDERR.reopen(@io) @stderr_hook = true self end |
#hook_stdout! ⇒ Object
34 35 36 37 38 39 |
# File 'lib/perfectqueue/daemons_logger.rb', line 34 def hook_stdout! return nil if @io == STDOUT STDOUT.reopen(@io) @stdout_hook = true self end |
#reopen ⇒ Object
60 61 62 63 64 65 66 67 68 |
# File 'lib/perfectqueue/daemons_logger.rb', line 60 def reopen begin reopen! return true rescue # TODO log? return false end end |
#reopen! ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/perfectqueue/daemons_logger.rb', line 47 def reopen! if @path @io.reopen(@path) if @stdout_hook STDOUT.reopen(@io) end if @stderr_hook STDERR.reopen(@io) end end nil end |