test/logger_test.rb in semantic_logger-0.2.0 vs test/logger_test.rb in semantic_logger-0.3.0
- old
+ new
@@ -7,11 +7,10 @@
require 'logger'
require 'semantic_logger'
require 'test/mock_logger'
# Unit Test for SemanticLogger::Logger
-#
class LoggerTest < Test::Unit::TestCase
context SemanticLogger::Logger do
context "log to Ruby and Rails logger" do
setup do
@@ -37,9 +36,39 @@
@logger.flush
assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ \w \[\d+:.+\] LoggerTest -- hello world -- Calculations -- \{:session_id=>\"HSSKLEU@JDK767\", :tracking_number=>12345\}\n/, @mock_logger.message
end
end
+ context "with_tags logging" do
+ should "add tags to log entries" do
+ @logger.with_tags('12345', 'DJHSFK') do
+ @logger.info('Hello world')
+ @logger.flush
+ assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ \w \[\d+:.+\] \[12345\] \[DJHSFK\] LoggerTest -- Hello world\n/, @mock_logger.message
+ end
+ end
+
+ should "add embedded tags to log entries" do
+ @logger.with_tags('First Level', 'tags') do
+ @logger.with_tags('Second Level') do
+ @logger.info('Hello world')
+ @logger.flush
+ assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ \w \[\d+:.+\] \[First Level\] \[tags\] \[Second Level\] LoggerTest -- Hello world\n/, @mock_logger.message
+ end
+ end
+ end
+
+ should "add payload to log entries" do
+ @logger.with_payload(:tracking_number => '123456') do
+ @logger.with_payload(:more => 'data', :even => 2) do
+ @logger.info('Hello world')
+ @logger.flush
+ assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ \w \[\d+:.+\] LoggerTest -- Hello world -- \{:more=>\"data\", :even=>2, :tracking_number=>\"123456\"\}\n/, @mock_logger.message
+ end
+ end
+ end
+
+ end
end
end
end
\ No newline at end of file