test/logger_test.rb in semantic_logger-4.3.0 vs test/logger_test.rb in semantic_logger-4.3.1
- old
+ new
@@ -7,10 +7,17 @@
let :dimensions do
{action: 'hit', user: 'jbloggs', state: 'FL'}
end
+ # Complex filters
+ module ComplexFilter
+ def self.call(log)
+ (/\AExclude/ =~ log.message).nil?
+ end
+ end
+
# Ensure that any log level can be logged
SemanticLogger::LEVELS.each do |level|
describe "##{level}" do
describe 'positional parameter' do
it 'logs message' do
@@ -163,10 +170,17 @@
logger.send(level, 'Exclude this log message', @hash) { 'Calculations' }
refute log_message
end
+ it 'Module' do
+ appender.filter = ComplexFilter
+ logger.send(level, 'Exclude this log message', @hash) { 'Calculations' }
+
+ refute log_message
+ end
+
it 'RegExp' do
filter = /\ALogger/
appender.filter = ->(log) { (/\AExclude/ =~ log.message).nil? }
logger.send(level, 'Exclude this log message', @hash) { 'Calculations' }
@@ -180,10 +194,17 @@
logger.send(level, 'Exclude this log message', @hash) { 'Calculations' }
refute log_message
end
+ it 'Module' do
+ logger.filter = ComplexFilter
+ logger.send(level, 'Exclude this log message', @hash) { 'Calculations' }
+
+ refute log_message
+ end
+
it 'RegExp' do
filter = /\ALogger/
logger.filter = ->(log) { (/\AExclude/ =~ log.message).nil? }
logger.send(level, 'Exclude this log message', @hash) { 'Calculations' }
@@ -285,13 +306,16 @@
end
it 'also supports named tagging' do
logger.tagged(level1: 1) do
assert_equal({level1: 1}, SemanticLogger.named_tags)
+ assert_equal({level1: 1}, logger.named_tags)
logger.tagged(level2: 2, more: 'data') do
assert_equal({level1: 1, level2: 2, more: 'data'}, SemanticLogger.named_tags)
+ assert_equal({level1: 1, level2: 2, more: 'data'}, logger.named_tags)
logger.tagged(level3: 3) do
assert_equal({level1: 1, level2: 2, more: 'data', level3: 3}, SemanticLogger.named_tags)
+ assert_equal({level1: 1, level2: 2, more: 'data', level3: 3}, logger.named_tags)
end
end
end
end