test/logger_test.rb in semantic_logger-2.18.0 vs test/logger_test.rb in semantic_logger-2.19.0
- old
+ new
@@ -95,19 +95,34 @@
assert_equal 'First Level', @logger.tags.first
assert_equal 'tags', @logger.tags.last
end
end
- it 'add payload to log entries' do
+ it 'logs tagged payload' do
hash = {tracking_number: "123456", even: 2, more: "data"}
hash_str = hash.inspect.sub("{", "\\{").sub("}", "\\}")
@logger.with_payload(tracking_number: '123456') do
@logger.with_payload(even: 2, more: 'data') do
@logger.info('Hello world')
SemanticLogger.flush
assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ I \[\d+:#{@thread_name}\] LoggerTest -- Hello world -- #{hash_str}/, @mock_logger.message
end
end
+ end
+
+ it 'logs payload' do
+ hash = {tracking_number: "123456", even: 2, more: "data"}
+ hash_str = hash.inspect.sub("{", "\\{").sub("}", "\\}")
+ @logger.info('Hello world', hash)
+ SemanticLogger.flush
+ assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ I \[\d+:#{@thread_name}\] LoggerTest -- Hello world -- #{hash_str}/, @mock_logger.message
+ end
+
+ it 'does not log an empty payload' do
+ hash = {}
+ @logger.info('Hello world', hash)
+ SemanticLogger.flush
+ assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ I \[\d+:#{@thread_name}\] LoggerTest -- Hello world/, @mock_logger.message
end
end
describe 'Ruby Logger' do
# Ensure that any log level can be logged