test/logger_test.rb in semantic_logger-2.9.0 vs test/logger_test.rb in semantic_logger-2.9.1
- old
+ new
@@ -10,26 +10,27 @@
# Unit Test for SemanticLogger::Logger
class LoggerTest < Test::Unit::TestCase
context SemanticLogger::Logger do
# Test each filter
[ nil, /\ALogger/, Proc.new{|l| (/\AExclude/ =~ l.message).nil? } ].each do |filter|
- context "filter: #{filter.inspect}" do
+ context "filter: #{filter.class.name}" do
setup do
# Use a mock logger that just keeps the last logged entry in an instance
# variable
SemanticLogger.default_level = :trace
@mock_logger = MockLogger.new
- SemanticLogger.add_appender(@mock_logger)
+ appender = SemanticLogger.add_appender(@mock_logger)
+ appender.filter = filter
# Add mock metric subscriber
$last_metric = nil
SemanticLogger.on_metric do |log_struct|
$last_metric = log_struct.dup
end
# Use this test's class name as the application name in the log output
- @logger = SemanticLogger::Logger.new(self.class, :trace, filter)
+ @logger = SemanticLogger[self.class]
@hash = { :session_id => 'HSSKLEU@JDK767', :tracking_number => 12345 }
@hash_str = @hash.inspect.sub("{", "\\{").sub("}", "\\}")
assert_equal [], @logger.tags
end
@@ -52,9 +53,19 @@
@logger.send(level, 'Exclude this log message', @hash) { "Calculations" }
SemanticLogger.flush
assert_nil @mock_logger.message
end
end
+
+ should "exclude log messages using RegExp filter" do
+ if filter.is_a?(Regexp)
+ logger = SemanticLogger::Logger.new('NotLogger', :trace, filter)
+ logger.send(level, 'Ignore all log messages from this class', @hash) { "Calculations" }
+ SemanticLogger.flush
+ assert_nil @mock_logger.message
+ end
+ end
+
end
end
context "tagged logging" do
should "add tags to log entries" do
\ No newline at end of file