From b7d9d6e2cd5082d269dafbc0316e2107febe1451 Mon Sep 17 00:00:00 2001 From: Terence Lee Date: Fri, 15 Mar 2013 04:07:22 -0700 Subject: make new rails apps log to STDOUT --- activesupport/lib/active_support/tagged_logging.rb | 8 ++++++++ activesupport/test/tagged_logging_test.rb | 11 +++++++++++ 2 files changed, 19 insertions(+) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/tagged_logging.rb b/activesupport/lib/active_support/tagged_logging.rb index 18bc919734..09bfc95231 100644 --- a/activesupport/lib/active_support/tagged_logging.rb +++ b/activesupport/lib/active_support/tagged_logging.rb @@ -54,6 +54,14 @@ module ActiveSupport end end + def self.create(f, formatter, level) + logger = ActiveSupport::Logger.new f + logger.formatter = formatter + logger = new(logger) + logger.level = ActiveSupport::Logger.const_get(level.to_s.upcase) + logger + end + def self.new(logger) # Ensure we set a default formatter so we aren't extending nil! logger.formatter ||= ActiveSupport::Logger::SimpleFormatter.new diff --git a/activesupport/test/tagged_logging_test.rb b/activesupport/test/tagged_logging_test.rb index 27f629474e..0f5b2cba8f 100644 --- a/activesupport/test/tagged_logging_test.rb +++ b/activesupport/test/tagged_logging_test.rb @@ -22,6 +22,17 @@ class TaggedLoggingTest < ActiveSupport::TestCase assert logger.formatter.respond_to?(:tagged) end + test 'creates a tagged logger with the appropriate level and formatter' do + stringio = StringIO.new + logger = ActiveSupport::TaggedLogging.create(stringio, ActiveSupport::Logger::SimpleFormatter.new, :debug) + logger.debug("foo") + + assert_not_nil logger.formatter + assert logger.formatter.respond_to?(:tagged) + assert_equal 0, logger.level + assert stringio.string.include?("foo") + end + test "tagged once" do @logger.tagged("BCX") { @logger.info "Funky time" } assert_equal "[BCX] Funky time\n", @output.string -- cgit v1.2.3