lib/tasks_scheduler/checker.rb in tasks_scheduler-0.2.3 vs lib/tasks_scheduler/checker.rb in tasks_scheduler-0.3.0

- old
+ new

@@ -1,11 +1,14 @@ +require 'tasks_scheduler/checker/log' + module TasksScheduler class Checker include Singleton CHECK_INTERVAL = 15 LOG_ON_FILE_ENV_KEY = 'TASKS_SCHEDULER_LOG_ON_FILE'.freeze + LOGS_KEYS = %w(rails stdout stderr).freeze def run check_log running = true Signal.trap('TERM') { running = false } @@ -16,18 +19,31 @@ sleep(CHECK_INTERVAL) end end def log_path - ::Rails.root.join('log', 'tasks_scheduler', 'checker.log') + rais_log.path end + def logs + LOGS_KEYS.map { |key| send("#{key}_log") } + end + + LOGS_KEYS.each do |log_key| + class_eval <<CODE, __FILE__, __LINE__ + 1 + def #{log_key}_log + @#{log_key}_log ||= ::TasksScheduler::Checker::Log.new('#{log_key}') + end +CODE + end + private def check_log return unless log_on_file? - ::FileUtils.mkdir_p(File.dirname(log_path)) - ::Rails.logger = ::Logger.new(log_path) + ::Rails.logger = ::Logger.new(rails_log.path) + $stdout.reopen(stdout_log.path, 'w') + $stderr.reopen(stderr_log.path, 'w') end def log_on_file? ENV[LOG_ON_FILE_ENV_KEY].present? end