Module: Raad::Logger

Extended by:
Logger
Included in:
Logger
Defined in:
lib/raad/logger.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args) ⇒ Object (private)



59
60
61
# File 'lib/raad/logger.rb', line 59

def method_missing(sym, *args)
  @log.send(sym, *args)
end

Instance Method Details

#level=(l) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/raad/logger.rb', line 25

def level=(l)
  levels = {
    :debug => Log4r::DEBUG,
    :info => Log4r::INFO,
    :warn => Log4r::WARN,
    :error => Log4r::ERROR,
  }
  @log.level = @verbose ? Log4r::DEBUG : levels[l]
end

#setup(options = {}) ⇒ Logger

Sets up the logging for the runner

Returns:

  • (Logger)

    The logger object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/raad/logger.rb', line 10

def setup(options = {})
  @log = Log4r::Logger.new('raad')

  # select only :pattern, :date_pattern, :date_method and flush nils
  formatter_options = {:pattern => "[#{Process.pid}:%l] %d :: %m"}.merge(options.reject{|k, v| !([:pattern, :date_pattern, :date_method].include?(k) && !v.nil?)})

  log_format = Log4r::PatternFormatter.new(formatter_options)
  setup_file_logger(@log, log_format, options[:file]) if options[:file]
  setup_stdout_logger(@log, log_format) if options[:stdout]

  @verbose = !!options[:verbose]
  @log.level = @verbose ? Log4r::DEBUG : Log4r::INFO
  @log
end