lib/semantic_logger/logger.rb in semantic_logger-0.7.0 vs lib/semantic_logger/logger.rb in semantic_logger-0.7.1
- old
+ new
@@ -159,11 +159,11 @@
def self.startup
@@appender_thread = Thread.new do
begin
logger.debug "SemanticLogger::Logger Appender thread started"
count = 0
- while message=queue.pop
+ while message = queue.pop
if message.is_a? Log
appenders.each {|appender| appender.log(message) }
count += 1
# Check every few log messages whether this appender thread is falling behind
if count > lag_check_interval
@@ -174,16 +174,16 @@
end
else
case message[:command]
when :shutdown
appenders.each {|appender| appender.flush }
- message[:reply_queue] << true
+ message[:reply_queue] << true if message[:reply_queue]
logger.debug "SemanticLogger::Logger appenders flushed, now shutting down"
break
when :flush
appenders.each {|appender| appender.flush }
- message[:reply_queue] << true
+ message[:reply_queue] << true if message[:reply_queue]
logger.debug "SemanticLogger::Logger appenders flushed"
end
end
end
rescue Exception => exception
@@ -199,16 +199,15 @@
# Stop the log appender thread and flush all appenders
def self.shutdown
return false unless @@appender_thread.alive?
logger.debug "SemanticLogger::Logger Shutdown. Stopping appender thread"
- reply_queue = Queue.new
- queue << { :command => :shutdown, :reply_queue => reply_queue }
- result = reply_queue.pop
+ queue << { :command => :shutdown }
+ @@appender_thread.join
# Undefine the class variable for the queue since in test environments
# at_exit can be invoked multiple times
remove_class_variable(:@@queue)
- result
+ true
end
# Formatting does not occur within this thread, it is done by each appender
# in the appender thread
def default_formatter