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.
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/perfectqueue/daemons_logger.rb', line 24 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
72 73 74 75 76 77 |
# File 'lib/perfectqueue/daemons_logger.rb', line 72 def close if @path @io.close unless @io.closed? end nil end |
#hook_stderr! ⇒ Object
43 44 45 46 47 |
# File 'lib/perfectqueue/daemons_logger.rb', line 43 def hook_stderr! STDERR.reopen(@io) @stderr_hook = true self end |
#hook_stdout! ⇒ Object
36 37 38 39 40 41 |
# File 'lib/perfectqueue/daemons_logger.rb', line 36 def hook_stdout! return nil if @io == STDOUT STDOUT.reopen(@io) @stdout_hook = true self end |
#reopen ⇒ Object
62 63 64 65 66 67 68 69 70 |
# File 'lib/perfectqueue/daemons_logger.rb', line 62 def reopen begin reopen! return true rescue # TODO log? return false end end |
#reopen! ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/perfectqueue/daemons_logger.rb', line 49 def reopen! if @path @io.reopen(@path) if @stdout_hook STDOUT.reopen(@io) end if @stderr_hook STDERR.reopen(@io) end end nil end |