Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Don't log to stdout when log_dir is set
Browse files Browse the repository at this point in the history
In addition to checking if log_file is set, we should check
for log_dir as well. Previously, If log_file is not set, oslo
will output logs to stdout even if log_dir is set. The only way
for example the Heat folks avoided logging to stdout was to
set log_file, but then all the heat processes ended up logging
to the same file. So a check for both log_dir and log_file
should avoid any output to stdout. Please note that use_stderr
should be set to false as well to avoid any output to console

Change-Id: Ie2886da679daedea0197ee3b3963ebedb8f11a0b
Closes-Bug: #1226287
  • Loading branch information
Davanum Srinivas committed Nov 24, 2013
1 parent bdabd51 commit a6f40ac
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion openstack/common/log.py
Expand Up @@ -477,7 +477,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)
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/test_log.py
Expand Up @@ -17,6 +17,7 @@
import logging
import os
import sys
import tempfile

import mock
from oslo.config import cfg
Expand Down Expand Up @@ -437,6 +438,16 @@ def test_log_file(self):
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])
Expand Down

0 comments on commit a6f40ac

Please sign in to comment.