Commits

Felix Krull committed 66bad85

Encode logfile as UTF-8.

Comments (0)

Files changed (2)

provence/core/cmdline.py

 def _configure_logging(options):
     """Set up the `logging` module as necessary."""
     atexit.register(logging.shutdown)
-    logging.basicConfig(
-        filename=options.log_file,
-        filemode="w",
-        level=logging.DEBUG)
+    root_logger = logging.getLogger()
+    root_logger.setLevel(logging.DEBUG)
+    logfile_handler = logging.FileHandler(options.log_file, mode="w",
+                                          encoding="utf-8")
+    root_logger.addHandler(logfile_handler)
 
 
 def main():

provence/tests/test_cmdline.py

+from imp import reload
 import logging
 import os.path
 import random
 import tempfile
-import warnings
 from .tools import StdoutTestCase, TestCase
 from provence.core.resource import Resource, AttributesNotSetError
 from provence.core.dependencies import CyclicDependencyError
             self.parser.parse_args()
 
 
-class TestConfigureLogging(TestCase):
+class TestConfigureLogging(StdoutTestCase):
     def setUp(self):
+        super().setUp()
         with tempfile.NamedTemporaryFile() as tmp:
             self.temp_name = tmp.name
 
         try:
             os.remove(self.temp_name)
         except OSError:
-            warnings.warn("TestExecScript failed to remove temp file")
+            pass
+        logging.shutdown()
+        reload(logging)
 
     @mock.patch("atexit.register")
     def test_configure_logging(self, register_mock):
         cmdline._configure_logging(opts)
         register_mock.assert_called_once_with(logging.shutdown)
 
+    def test_high_unicode_message(self):
+        opts = mock.Mock(log_file=self.temp_name)
+        cmdline._configure_logging(opts)
+        logging.info("test äöü".encode("latin1")
+                     .decode("utf-8", errors="replace"))
+        self.assert_stdout_equal("")
+        self.assert_stderr_equal("")
+
 
 class TestProvenceCommandLine(StdoutTestCase):
     @mock.patch("sys.argv", ["provence"])