module Resqued::Logging

Mixin for any class that wants to write messages to the log file.

Public Class Methods

build_logger() click to toggle source
# 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() click to toggle source

Public: Make sure the log IO is closed.

# File lib/resqued/logging.rb, line 61
def close_log
  if @logging_io && @logging_io != $stdout
    @logging_io.close
    @logging_io = nil
  end
end
log_file() click to toggle source

Public.

# File lib/resqued/logging.rb, line 75
def log_file
  ENV["RESQUED_LOGFILE"]
end
log_file=(path) click to toggle source

Public.

# File lib/resqued/logging.rb, line 69
def log_file=(path)
  ENV["RESQUED_LOGFILE"] = File.expand_path(path)
  close_log
end
logger() click to toggle source

Public: Get a ‘Logger`.

# File lib/resqued/logging.rb, line 9
def logger
  @logger ||= build_logger
end
logging_io() click to toggle source

Private: Get an IO to write log messages to.

# File lib/resqued/logging.rb, line 44
def logging_io
  @logging_io = nil if @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

Public Instance Methods

log(level, message = nil) click to toggle source

Private (in classes that include this module)

# File lib/resqued/logging.rb, line 91
def log(level, message = nil)
  level, message = :info, level if message.nil?
  Resqued::Logging.logger.send(level, self.class.name) { message }
end
log_to_stdout?() click to toggle source

Public.

# File lib/resqued/logging.rb, line 81
def log_to_stdout?
  Resqued::Logging.log_file.nil?
end
reopen_logs() click to toggle source

Public: Re-open all log files.

# File lib/resqued/logging.rb, line 86
def reopen_logs
  Resqued::Logging.close_log # it gets opened the next time it's needed.
end