Skip to content

Commit

Permalink
Don't create a logfile when redirect_stderr=true and stderr_logfile=auto
Browse files Browse the repository at this point in the history
Closes #282
Closes #643
  • Loading branch information
mnaberez committed Aug 13, 2015
1 parent f6647b5 commit 1a764af
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
- Fixed ``DeprecationWarning: Parameters to load are deprecated. Call
.resolve and .require separately.`` on setuptools >= 11.3.

- If ``redirect_stderr=true`` and ``stderr_logfile=auto``, no stderr log
file will be created. In previous versions, an empty stderr log file
would be created. Thanks to Łukasz Kożuchowski for the initial patch.

3.1.3 (2014-10-28)
------------------

Expand Down
9 changes: 9 additions & 0 deletions supervisor/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,15 @@ def get(section, opt, *args, **kwargs):
'rollover, set maxbytes > 0 to avoid filling up '
'filesystem unintentionally' % (section, n))

if redirect_stderr:
if logfiles['stderr_logfile'] not in (Automatic, None):
self.parse_warnings.append(
'For [%s], redirect_stderr=true but stderr_logfile has '
'also been set to a filename, the filename has been '
'ignored' % section)
# never create an stderr logfile when redirected
logfiles['stderr_logfile'] = None

command = get(section, 'command', None, expansions=expansions)
if command is None:
raise ValueError(
Expand Down
32 changes: 32 additions & 0 deletions supervisor/tests/test_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -999,6 +999,38 @@ def test_processes_from_section_expands_env_in_environment(self):
expected = "/foo/bar:%s" % os.environ['PATH']
self.assertEqual(pconfigs[0].environment['PATH'], expected)

def test_processes_from_section_redirect_stderr_with_filename(self):
instance = self._makeOne()
text = lstrip("""\
[program:foo]
command = /bin/foo
redirect_stderr = true
stderr_logfile = /tmp/logfile
""")
from supervisor.options import UnhosedConfigParser
config = UnhosedConfigParser()
config.read_string(text)
pconfigs = instance.processes_from_section(config, 'program:foo', 'bar')
self.assertEqual(instance.parse_warnings[0],
'For [program:foo], redirect_stderr=true but stderr_logfile has '
'also been set to a filename, the filename has been ignored')
self.assertEqual(pconfigs[0].stderr_logfile, None)

def test_processes_from_section_redirect_stderr_with_auto(self):
instance = self._makeOne()
text = lstrip("""\
[program:foo]
command = /bin/foo
redirect_stderr = true
stderr_logfile = auto
""")
from supervisor.options import UnhosedConfigParser
config = UnhosedConfigParser()
config.read_string(text)
pconfigs = instance.processes_from_section(config, 'program:foo', 'bar')
self.assertEqual(instance.parse_warnings, [])
self.assertEqual(pconfigs[0].stderr_logfile, None)

@patch.dict('os.environ', { 'HOME': tempfile.gettempdir(),
'USER': 'johndoe',
'HTSRV_PORT': '9210',
Expand Down

0 comments on commit 1a764af

Please sign in to comment.