diff --git a/openstack/common/log.py b/openstack/common/log.py index b24b6551..f9f226b8 100644 --- a/openstack/common/log.py +++ b/openstack/common/log.py @@ -475,7 +475,7 @@ def _setup_logging_from_conf(): streamlog = ColorHandler() log_root.addHandler(streamlog) - elif not CONF.log_file: + elif not logpath: # pass sys.stdout as a positional argument # python2.6 calls the argument strm, in 2.7 it's stream streamlog = logging.StreamHandler(sys.stdout) diff --git a/tests/unit/test_log.py b/tests/unit/test_log.py index 751732b9..aea4f98b 100644 --- a/tests/unit/test_log.py +++ b/tests/unit/test_log.py @@ -17,6 +17,7 @@ import logging import os import sys +import tempfile import mock from oslo.config import cfg @@ -437,6 +438,16 @@ class LogConfigOptsTestCase(test.BaseTestCase): self.CONF(['--log-file', log_file]) self.assertEqual(self.CONF.log_file, log_file) + def test_log_dir_handlers(self): + log_dir = tempfile.mkdtemp() + self.CONF(['--log-dir', log_dir]) + self.CONF.set_default('use_stderr', False) + log._setup_logging_from_conf() + logger = log._loggers[None].logger + self.assertEqual(1, len(logger.handlers)) + self.assertIsInstance(logger.handlers[0], + logging.handlers.WatchedFileHandler) + def test_logfile_deprecated(self): logfile = '/some/other/path/foo-bar.log' self.CONF(['--logfile', logfile])