lib/semantic_logger/logger.rb in semantic_logger-0.8.0 vs lib/semantic_logger/logger.rb in semantic_logger-0.8.1
- old
+ new
@@ -47,10 +47,11 @@
ThreadSafe::Array.new
end
# Initial default Level for all new instances of SemanticLogger::Logger
@@default_level = :info
+ @@appender_thread = nil
# Allow for setting the global default log level
# This change only applies to _new_ loggers, existing logger levels
# will not be changed in any way
def self.default_level=(level)
@@ -97,11 +98,11 @@
end
# Flush all queued log entries disk, database, etc.
# All queued log messages are written and then each appender is flushed in turn
def self.flush
- return false unless started?
+ return false unless started? && @@appender_thread && @@appender_thread.alive?
reply_queue = Queue.new
queue << { :command => :flush, :reply_queue => reply_queue }
reply_queue.pop
end
@@ -170,10 +171,10 @@
# This thread is designed to never go down unless the main thread terminates
# Before terminating at_exit is used to flush all the appenders
#
# Should any appender fail to log or flush, the exception is logged and
# other appenders will still be called
- Thread.new do
+ @@appender_thread = Thread.new do
logger.debug "SemanticLogger::Logger Appender thread started"
begin
count = 0
while message = queue.pop
if message.is_a? Log