class BoxGrinder::LogHelper

Constants

THRESHOLDS

Public Class Methods

new(options = {}) click to toggle source
# File lib/boxgrinder-core/helpers/log-helper.rb, line 54
def initialize(options = {})
  location      = options[:location] || 'log/boxgrinder.log'
  threshold     = options[:level].nil? ? :info : options[:level].to_sym
  type          = options[:type] || [:stdout, :file]

  unless type.is_a?(Array)
    type = [type.to_s.to_sym]
  end

  threshold = THRESHOLDS[threshold.to_sym] unless threshold.nil?
  formatter = Logger::Formatter.new

  if type.include?(:file)
    FileUtils.mkdir_p(File.dirname(location))

    @file_log             = Logger.new(location, 10, 1024000)
    @file_log.level       = Logger::TRACE
    @file_log.formatter   = formatter
  end

  if type.include?(:stdout)
    @stdout_log           = Logger.new(STDOUT.dup)
    @stdout_log.level     = threshold || Logger::INFO
    @stdout_log.formatter = formatter
  end
end

Public Instance Methods

method_missing(method_name, *args) click to toggle source
# File lib/boxgrinder-core/helpers/log-helper.rb, line 86
def method_missing(method_name, *args)
  @stdout_log.send(method_name, *args) unless @stdout_log.nil?
  @file_log.send(method_name, *args) unless @file_log.nil?
end
write( msg ) click to toggle source
# File lib/boxgrinder-core/helpers/log-helper.rb, line 81
def write( msg )
  @stdout_log.trace( msg.chomp.strip ) unless @stdout_log.nil?
  @file_log.trace( msg.chomp.strip ) unless @file_log.nil?
end