Explorar o código

Don't create a logfile when redirect_stderr=true and stderr_logfile=auto
Closes #282
Closes #643

Mike Naberezny %!s(int64=9) %!d(string=hai) anos
pai
achega
1a764af3c5
Modificáronse 3 ficheiros con 45 adicións e 0 borrados
  1. 4 0
      CHANGES.txt
  2. 9 0
      supervisor/options.py
  3. 32 0
      supervisor/tests/test_options.py

+ 4 - 0
CHANGES.txt

@@ -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)
 ------------------
 

+ 9 - 0
supervisor/options.py

@@ -923,6 +923,15 @@ class ServerOptions(Options):
                         '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(

+ 32 - 0
supervisor/tests/test_options.py

@@ -999,6 +999,38 @@ class ServerOptionsTests(unittest.TestCase):
         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',