Module: Resqued::Logging
- Included in:
- Listener, ListenerProxy, Master, Worker
- Defined in:
- lib/resqued/logging.rb
Overview
Mixin for any class that wants to write messages to the log file.
Defined Under Namespace
Classes: ResquedLogFormatter, ResquedLoggingIOWrapper
Class Method Summary collapse
- .build_logger ⇒ Object
-
.close_log ⇒ Object
Public: Make sure the log IO is closed.
-
.log_file ⇒ Object
Public.
-
.log_file=(path) ⇒ Object
Public.
-
.logger ⇒ Object
Public: Get a ‘Logger`.
-
.logging_io ⇒ Object
Private: Get an IO to write log messages to.
Instance Method Summary collapse
-
#log(level, message = nil) ⇒ Object
Private (in classes that include this module).
-
#log_to_stdout? ⇒ Boolean
Public.
-
#reopen_logs ⇒ Object
Public: Re-open all log files.
Class Method Details
.build_logger ⇒ Object
13 14 15 16 17 |
# File 'lib/resqued/logging.rb', line 13 def build_logger MonoLogger.new(ResquedLoggingIOWrapper.new).tap do |logger| logger.formatter = ResquedLogFormatter.new end end |
.close_log ⇒ Object
Public: Make sure the log IO is closed.
54 55 56 57 58 59 |
# File 'lib/resqued/logging.rb', line 54 def close_log if @logging_io && @logging_io != $stdout @logging_io.close @logging_io = nil end end |
.log_file ⇒ Object
Public.
68 69 70 |
# File 'lib/resqued/logging.rb', line 68 def log_file ENV['RESQUED_LOGFILE'] end |
.log_file=(path) ⇒ Object
Public.
62 63 64 65 |
# File 'lib/resqued/logging.rb', line 62 def log_file=(path) ENV['RESQUED_LOGFILE'] = File.(path) close_log end |
.logger ⇒ Object
Public: Get a ‘Logger`.
9 10 11 |
# File 'lib/resqued/logging.rb', line 9 def logger @logger ||= build_logger end |
.logging_io ⇒ Object
Private: Get an IO to write log messages to.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/resqued/logging.rb', line 37 def logging_io @logging_io = nil if @logging_io && @logging_io.closed? @logging_io ||= if path = Resqued::Logging.log_file File.open(path, 'a').tap do |f| f.sync = true f.close_on_exec = true # Make sure we're not holding onto a stale filehandle. $stdout.reopen(f) $stderr.reopen(f) end else $stdout end end |
Instance Method Details
#log(level, message = nil) ⇒ Object
Private (in classes that include this module)
84 85 86 87 |
# File 'lib/resqued/logging.rb', line 84 def log(level, = nil) level, = :info, level if .nil? Resqued::Logging.logger.send(level, self.class.name) { } end |