← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~julian-edwards/launchpad/fix-logger into lp:launchpad/devel

 

Julian Edwards has proposed merging lp:~julian-edwards/launchpad/fix-logger into lp:launchpad/devel.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  #654605 FakeLogger blows up when logging strings with a %
  https://bugs.launchpad.net/bugs/654605


= Summary =
Make the logger work with percent signs in the logged message.

== Proposed fix ==
The FakeLogger currently blows up when there's a percent sign in the message 
as it thinks there's a substitution.

== Implementation details ==
Trivial exercise in escaping the percent.

== Tests ==
bin/test -cvv test_logger TestFakeLogger
-- 
https://code.launchpad.net/~julian-edwards/launchpad/fix-logger/+merge/37487
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~julian-edwards/launchpad/fix-logger into lp:launchpad/devel.
=== modified file 'lib/canonical/launchpad/scripts/logger.py'
--- lib/canonical/launchpad/scripts/logger.py	2010-09-27 08:46:26 +0000
+++ lib/canonical/launchpad/scripts/logger.py	2010-10-04 15:41:16 +0000
@@ -39,6 +39,7 @@
 from optparse import OptionParser
 import os.path
 import re
+import string
 import sys
 import time
 import traceback
@@ -87,6 +88,7 @@
             output_file = sys.stdout
         else:
             output_file = self.output_file
+        msg = string.replace(msg, "%", "%%")
         print >> output_file, prefix, msg % stuff
 
         if 'exc_info' in kw:

=== added file 'lib/canonical/launchpad/scripts/tests/test_logger.py'
--- lib/canonical/launchpad/scripts/tests/test_logger.py	1970-01-01 00:00:00 +0000
+++ lib/canonical/launchpad/scripts/tests/test_logger.py	2010-10-04 15:41:16 +0000
@@ -0,0 +1,20 @@
+# Copyright 2010 Canonical Ltd.  This software is licensed under the
+# GNU Affero General Public License version 3 (see the file LICENSE).
+
+__metaclass__ = type
+__all__ = []
+
+from canonical.launchpad.scripts.logger import QuietFakeLogger
+from lp.testing import TestCase
+
+
+class TestFakeLogger(TestCase):
+
+    def test_logging_strings_with_percent_tokens(self):
+        # Logging a string that has '%' tokens in it should not cause an
+        # exception because of unsubstituted interpolations.
+        TEST_STRING = "testing % token"
+        logger = QuietFakeLogger()
+        logger.log(TEST_STRING)
+        logger.output_file.seek(0)
+        self.assertTrue(TEST_STRING in logger.output_file.read())

=== renamed file 'lib/canonical/launchpad/scripts/tests/test_logger.py' => 'lib/canonical/launchpad/scripts/tests/test_logger_doc.py'