lib/semantic_logger/logger.rb in semantic_logger-0.8.1 vs lib/semantic_logger/logger.rb in semantic_logger-0.9.0
- old
+ new
@@ -45,28 +45,10 @@
# Thread safe appenders array
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)
- @@default_level = level
- end
-
- # Returns the global default log level for new Logger instances
- def self.default_level
- @@default_level
- end
-
- attr_reader :name
-
# Returns a Logger instance
#
# Return the logger for a specific class, supports class specific log levels
# logger = SemanticLogger::Logger.new(self)
# OR
@@ -91,19 +73,26 @@
#
# When this number grows it is because the logging appender thread is not
# able to write to the appenders fast enough. Either reduce the amount of
# logging, increase the log level, reduce the number of appenders, or
# look into speeding up the appenders themselves
- def self.cache_count
+ def self.queue_size
queue.size
end
+ # DEPRECATED: Please use queue_size instead.
+ def self.cache_count
+ warn "[DEPRECATION] 'SemanticLogger::Logger.cache_count' is deprecated. Please use 'SemanticLogger::Logger.queue_size' instead."
+ queue_size
+ 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? && @@appender_thread && @@appender_thread.alive?
+ logger.debug "SemanticLogger::Logger Flushing appenders with #{queue_size} log messages on the queue"
reply_queue = Queue.new
queue << { :command => :flush, :reply_queue => reply_queue }
reply_queue.pop
end
@@ -138,10 +127,11 @@
end
############################################################################
protected
+ @@appender_thread = nil
@@queue = Queue.new
# Queue to hold messages that need to be logged to the various appenders
def self.queue
@@queue
@@ -188,11 +178,11 @@
end
count += 1
# Check every few log messages whether this appender thread is falling behind
if count > lag_check_interval
if (diff = Time.now - message.time) > lag_threshold_s
- logger.warn "SemanticLogger::Logger Appender thread has fallen behind by #{diff} seconds with #{cache_count} messages queued up. Consider reducing the log level or changing the appenders"
+ logger.warn "SemanticLogger::Logger Appender thread has fallen behind by #{diff} seconds with #{queue_size} messages queued up. Consider reducing the log level or changing the appenders"
end
count = 0
end
else
case message[:command]
@@ -222,15 +212,9 @@
at_exit do
logger.debug "SemanticLogger::Logger process terminating, flushing appenders"
flush
end
- end
-
- # Formatting does not occur within this thread, it is done by each appender
- # in the appender thread
- def default_formatter
- nil
end
end
end