Namespace
- CLASS LoggerTest::Logger
Methods
- S
- T
-
- test_broadcast_silencing_does_not_break_plain_ruby_logger,
- test_buffer_multibyte,
- test_logger_level_local_thread_safety,
- test_logger_level_main_thread_safety,
- test_logger_level_per_object_thread_safety,
- test_logger_silencing_works_for_broadcast,
- test_should_add_message_passed_as_block_when_using_add,
- test_should_add_message_passed_as_block_when_using_shortcut,
- test_should_convert_message_to_string,
- test_should_convert_message_to_string_when_passed_in_block,
- test_should_know_if_its_loglevel_is_below_a_given_level,
- test_should_log_debugging_message_when_debugging,
- test_should_not_evaluate_block_if_message_wont_be_logged,
- test_should_not_log_debug_messages_when_log_level_is_info,
- test_should_not_mutate_message,
- test_silencing_everything_but_errors,
- test_write_binary_data_create_file,
- test_write_binary_data_to_existing_file
Included Modules
Constants
| Logger | = | ActiveSupport::Logger |
Instance Public methods
setup()
Link
test_broadcast_silencing_does_not_break_plain_ruby_logger()
Link
# File activesupport/test/logger_test.rb, line 158 def test_broadcast_silencing_does_not_break_plain_ruby_logger another_output = StringIO.new another_logger = ::Logger.new(another_output) @logger.extend Logger.broadcast(another_logger) @logger.debug "CORRECT DEBUG" @logger.silence do |logger| assert_kind_of ActiveSupport::Logger, logger @logger.debug "FAILURE" @logger.error "CORRECT ERROR" end assert @output.string.include?("CORRECT DEBUG") assert @output.string.include?("CORRECT ERROR") assert_not @output.string.include?("FAILURE") assert another_output.string.include?("CORRECT DEBUG") assert another_output.string.include?("CORRECT ERROR") assert another_output.string.include?("FAILURE") # We can't silence plain ruby Logger cause with thread safety # but at least we don't break it end
test_buffer_multibyte()
Link
# File activesupport/test/logger_test.rb, line 116 def test_buffer_multibyte @logger.level = Logger::INFO @logger.info(UNICODE_STRING) @logger.info(BYTE_STRING) assert @output.string.include?(UNICODE_STRING) byte_string = @output.string.dup byte_string.force_encoding("ASCII-8BIT") assert byte_string.include?(BYTE_STRING) end
test_logger_level_local_thread_safety()
Link
# File activesupport/test/logger_test.rb, line 216 def test_logger_level_local_thread_safety @logger.level = Logger::INFO assert_level(Logger::INFO) thread_1_latch = ActiveSupport::Concurrency::Latch.new thread_2_latch = ActiveSupport::Concurrency::Latch.new threads = (1..2).collect do |thread_number| Thread.new do # force thread 2 to wait until thread 1 is already in @logger.silence thread_2_latch.await if thread_number == 2 @logger.silence(Logger::ERROR) do assert_level(Logger::ERROR) @logger.silence(Logger::DEBUG) do # allow thread 2 to finish but hold thread 1 if thread_number == 1 thread_2_latch.release thread_1_latch.await end assert_level(Logger::DEBUG) end end # allow thread 1 to finish assert_level(Logger::INFO) thread_1_latch.release if thread_number == 2 end end threads.each(&:join) assert_level(Logger::INFO) end
test_logger_level_main_thread_safety()
Link
# File activesupport/test/logger_test.rb, line 194 def test_logger_level_main_thread_safety @logger.level = Logger::INFO assert_level(Logger::INFO) latch = ActiveSupport::Concurrency::Latch.new latch2 = ActiveSupport::Concurrency::Latch.new t = Thread.new do latch.await assert_level(Logger::INFO) latch2.release end @logger.silence(Logger::ERROR) do assert_level(Logger::ERROR) latch.release latch2.await end t.join end
test_logger_level_per_object_thread_safety()
Link
# File activesupport/test/logger_test.rb, line 182 def test_logger_level_per_object_thread_safety logger1 = Logger.new(StringIO.new) logger2 = Logger.new(StringIO.new) level = Logger::DEBUG assert_equal level, logger1.level, "Expected level #{level_name(level)}, got #{level_name(logger1.level)}" assert_equal level, logger2.level, "Expected level #{level_name(level)}, got #{level_name(logger2.level)}" logger1.level = Logger::ERROR assert_equal level, logger2.level, "Expected level #{level_name(level)}, got #{level_name(logger2.level)}" end
test_logger_silencing_works_for_broadcast()
Link
# File activesupport/test/logger_test.rb, line 136 def test_logger_silencing_works_for_broadcast another_output = StringIO.new another_logger = Logger.new(another_output) @logger.extend Logger.broadcast(another_logger) @logger.debug "CORRECT DEBUG" @logger.silence do |logger| assert_kind_of ActiveSupport::Logger, logger @logger.debug "FAILURE" @logger.error "CORRECT ERROR" end assert @output.string.include?("CORRECT DEBUG") assert @output.string.include?("CORRECT ERROR") assert_not @output.string.include?("FAILURE") assert another_output.string.include?("CORRECT DEBUG") assert another_output.string.include?("CORRECT ERROR") assert_not another_output.string.include?("FAILURE") end
test_should_add_message_passed_as_block_when_using_add()
Link
test_should_add_message_passed_as_block_when_using_shortcut()
Link
test_should_convert_message_to_string()
Link
test_should_convert_message_to_string_when_passed_in_block()
Link
test_should_know_if_its_loglevel_is_below_a_given_level()
Link
# File activesupport/test/logger_test.rb, line 108 def test_should_know_if_its_loglevel_is_below_a_given_level Logger::Severity.constants.each do |level| next if level.to_s == 'UNKNOWN' @logger.level = Logger::Severity.const_get(level) - 1 assert @logger.send("#{level.downcase}?"), "didn't know if it was #{level.downcase}? or below" end end
test_should_log_debugging_message_when_debugging()
Link
test_should_not_evaluate_block_if_message_wont_be_logged()
Link
test_should_not_log_debug_messages_when_log_level_is_info()
Link
test_should_not_mutate_message()
Link
test_silencing_everything_but_errors()
Link
test_write_binary_data_create_file()
Link
# File activesupport/test/logger_test.rb, line 41 def test_write_binary_data_create_file fname = File.join Dir.tmpdir, 'lol', 'rofl.log' FileUtils.mkdir_p File.dirname(fname) f = File.open(fname, 'w') f.binmode logger = Logger.new f logger.level = Logger::DEBUG str = "\x80" str.force_encoding("ASCII-8BIT") logger.add Logger::DEBUG, str ensure logger.close File.unlink fname end
test_write_binary_data_to_existing_file()
Link
# File activesupport/test/logger_test.rb, line 20 def test_write_binary_data_to_existing_file t = Tempfile.new ['development', 'log'] t.binmode t.write 'hi mom!' t.close f = File.open(t.path, 'w') f.binmode logger = Logger.new f logger.level = Logger::DEBUG str = "\x80" str.force_encoding("ASCII-8BIT") logger.add Logger::DEBUG, str ensure logger.close t.close true end