Use logger

This commit is contained in:
Dzmitry Plashchynski
2015-03-03 19:36:50 +02:00
parent cbc33324cc
commit 3b0c0465ca
2 changed files with 13 additions and 9 deletions

View File

@@ -10,25 +10,29 @@ module Crono
attr_accessor :schedule
attr_accessor :logger
def run
def initialize
self.config = Config.new
self.schedule = Schedule.new
Crono.schedule = schedule
end
def run
parse_options(ARGV)
logfile = config.daemonize ? config.logfile : STDOUT
self.logger = Logger.new(logfile)
init_logger
load_rails
print_banner
start_working_loop
end
private
def init_logger
logfile = config.daemonize ? config.logfile : STDOUT
self.logger = Logger.new(logfile)
end
def print_banner
puts "Loading Crono #{Crono::VERSION}"
puts "Running in #{RUBY_DESCRIPTION}"
logger.info "Loading Crono #{Crono::VERSION}"
logger.info "Running in #{RUBY_DESCRIPTION}"
end
def load_rails
@@ -39,7 +43,7 @@ module Crono
end
def run_job(klass)
puts "Perform #{klass}"
logger.info "Perform #{klass}"
Thread.new { klass.new.perform }
end

View File

@@ -1,7 +1,7 @@
module Crono
class Config
CRONOTAB = "config/cronotab.rb"
LOGFILE = "log/crono.rb"
LOGFILE = "log/crono.log"
attr_accessor :cronotab
attr_accessor :logfile