Class: ResqueAdmin::Scheduler::LoggerBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/resque/scheduler/logger_builder.rb,
lib/resque/scheduler_admin/logger_builder.rb,
lib/resque_admin/scheduler/logger_builder.rb

Overview

Just builds a logger, with specified verbosity and destination. The simplest example:

ResqueAdmin::Scheduler::LoggerBuilder.new.build

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ LoggerBuilder

Initializes new instance of the builder

Pass :opts Hash with

- :quiet if logger needs to be silent for all levels. Default - false
- :verbose if there is a need in debug messages. Default - false
- :log_dev to output logs into a desired file. Default - STDOUT
- :format log format, either 'text' or 'json'. Default - 'text'

Example:

LoggerBuilder.new(
  :quiet => false, :verbose => true, :log_dev => 'log/scheduler.log'
)


25
26
27
28
29
30
# File 'lib/resque/scheduler/logger_builder.rb', line 25

def initialize(opts = {})
  @quiet = !!opts[:quiet]
  @verbose = !!opts[:verbose]
  @log_dev = opts[:log_dev] || $stdout
  @format = opts[:format] || 'text'
end

Instance Method Details

#buildObject

Returns an instance of MonoLogger



33
34
35
36
37
38
# File 'lib/resque/scheduler/logger_builder.rb', line 33

def build
  logger = MonoLogger.new(@log_dev)
  logger.level = level
  logger.formatter = send(:"#{@format}_formatter")
  logger
end