lib/semantic_logger/appender/async.rb in semantic_logger-4.6.1 vs lib/semantic_logger/appender/async.rb in semantic_logger-4.7.0

- old
+ new

@@ -1,6 +1,6 @@ -require 'forwardable' +require "forwardable" module SemanticLogger module Appender # Allow any appender to run asynchronously in a separate thread. class Async @@ -71,10 +71,11 @@ # Returns [Thread] the worker thread. # # Starts the worker thread if not running. def thread return @thread if @thread&.alive? + @thread = Thread.new { process } end # Returns true if the worker thread is active def active? @@ -113,33 +114,33 @@ # Separate thread for batching up log messages before writing. def process # This thread is designed to never go down unless the main thread terminates # or the appender is closed. Thread.current.name = logger.name - logger.trace 'Async: Appender thread active' + logger.trace "Async: Appender thread active" begin process_messages - rescue StandardError => exception + rescue StandardError => e # This block may be called after the file handles have been released by Ruby begin - logger.error('Async: Restarting due to exception', exception) + logger.error("Async: Restarting due to exception", e) rescue StandardError nil end retry - rescue Exception => exception + rescue Exception => e # This block may be called after the file handles have been released by Ruby begin - logger.error('Async: Stopping due to fatal exception', exception) + logger.error("Async: Stopping due to fatal exception", e) rescue StandardError nil end ensure @thread = nil # This block may be called after the file handles have been released by Ruby begin - logger.trace('Async: Thread has stopped') + logger.trace("Async: Thread has stopped") rescue StandardError nil end end end @@ -157,10 +158,10 @@ end else break unless process_message(message) end end - logger.trace 'Async: Queue Closed' + logger.trace "Async: Queue Closed" end # Returns false when message processing should be stopped def process_message(message) case message[:command]