lib/caddy/task_observer.rb in caddy-1.5.5 vs lib/caddy/task_observer.rb in caddy-1.6.0
- old
+ new
@@ -1,8 +1,10 @@
# frozen_string_literal: true
module Caddy
- class TaskObserver #:nodoc:
+ # {TaskObserver} is used internally to monitor the status of the running refreshers
+ # @private
+ class TaskObserver
def initialize(error_handler, cache_name)
@error_handler = error_handler || Caddy.error_handler
@cache_name = cache_name
end
@@ -12,30 +14,34 @@
if @error_handler
if @error_handler.respond_to?(:call)
begin
@error_handler.call(boom)
rescue => incepted_boom
- puts_exception("Caddy error handler itself errored handling refresh for :#{@cache_name}", incepted_boom)
+ log_exception("Caddy error handler itself errored handling refresh for :#{@cache_name}", incepted_boom)
end
else
# rubocop:disable Style/StringLiterals
- STDERR.puts 'Caddy error handler not callable. Please set the error handler like:'\
- ' `Caddy.error_handler = -> (e) { puts "#{e}" }`'
+ logger.error 'Caddy error handler not callable. Please set the error handler like:'\
+ ' `Caddy.error_handler = -> (e) { puts "#{e}" }`'
# rubocop:enable Style/StringLiterals
- puts_exception("Caddy refresher for :#{@cache_name} failed with error", boom)
+ log_exception("Caddy refresher for :#{@cache_name} failed with error", boom)
end
elsif boom.is_a?(Concurrent::TimeoutError)
- STDERR.puts "Caddy refresher for :#{@cache_name} timed out"
+ logger.error "Caddy refresher for :#{@cache_name} timed out"
else
- puts_exception("Caddy refresher for :#{@cache_name} failed with error", boom)
+ log_exception("Caddy refresher for :#{@cache_name} failed with error", boom)
end
end
private
- def puts_exception(msg, boom)
- STDERR.puts "\n#{msg}: #{boom}"
- STDERR.puts "\t#{boom.backtrace.join("\n\t")}"
+ def log_exception(msg, boom)
+ logger.error "\n#{msg}: #{boom}"
+ logger.error "\t#{boom.backtrace.join("\n\t")}"
+ end
+
+ def logger
+ Caddy.logger
end
end
end