Kaynağa Gözat

Make logging of stdout optional.

Chris McDonough 19 yıl önce
ebeveyn
işleme
be0d96a18f
5 değiştirilmiş dosya ile 23 ekleme ve 12 silme
  1. 14 7
      README.txt
  2. 0 2
      TODO.txt
  3. 5 1
      src/supervisor/options.py
  4. 2 1
      src/supervisor/supervisord.py
  5. 2 1
      src/supervisor/tests.py

+ 14 - 7
README.txt

@@ -295,6 +295,7 @@ Configuration File '[program:x]' Section Settings
     stopsignal=TERM
     stopwaitsecs=10
     user=nobody
+    log_stdout=true
     log_stderr=false
     logfile=/tmp/programname.log
     logfile_maxbytes=10MB
@@ -350,14 +351,20 @@ Configuration File '[program:x]' Section Settings
   is not running as root, this option has no effect.  Defaut: do not
   switch users.
 
-  'log_stderr' -- Send process stderr output to the process logfile
-  (intermingled with stdout output).  Default: false.
+  'log_stdout' -- Send process stdout output to the process logfile.
+  Default: true.
 
-  'logfile' -- Keep process stdout (and stderr if log_stderr is true)
-  in this file.  If this is unset or set to 'AUTO', supervisor will
-  automatically choose a file location.  Set this to NONE to create no
-  log file.  AUTO log files and their backups will be deleted when
-  supervisord restarts.  Default: AUTO.
+  'log_stderr' -- Send process stderr output to the process logfile.
+  Default: false.
+
+  'logfile' -- Keep process output as determined by log_stdout and
+  log_stderr in this file.  NOTE: if both log_stderr and log_stdout
+  are true, the output from child stderr and stdout will be
+  intermingled more or less randomly in the log.  If this is unset or
+  set to 'AUTO', supervisor will automatically choose a file location.
+  If this is set to 'NONE', supervisord will create no log file.  AUTO
+  log files and their backups will be deleted when supervisord
+  restarts.  Default: AUTO.
 
   'logfile_maxbytes' -- The maximum number of bytes that may be
   consumed by the process log file before it is rotated (suffix

+ 0 - 2
TODO.txt

@@ -5,8 +5,6 @@
 
    - provide "restart all" functionality
 
-- Make logging of stdout optional on a per-process basis (but default yes).
-
 - Rewrite the delay/backoff stuff so humans can understand it.
 
 - Remove backofflimit.

+ 5 - 1
src/supervisor/options.py

@@ -715,6 +715,8 @@ class ServerOptions(Options):
                 exitcodes = datatypes.list_of_ints(exitcodes)
             except:
                 raise ValueError("exitcodes must be a list of ints e.g. 1,2")
+            log_stdout = config.saneget(section, 'log_stdout', 'true')
+            log_stdout = datatypes.boolean(log_stdout)
             log_stderr = config.saneget(section, 'log_stderr', 'false')
             log_stderr = datatypes.boolean(log_stderr)
             pconfig = ProcessConfig(name=name, command=command,
@@ -729,6 +731,7 @@ class ServerOptions(Options):
                                     stopsignal=stopsignal,
                                     stopwaitsecs=stopwaitsecs,
                                     exitcodes=exitcodes,
+                                    log_stdout=log_stdout,
                                     log_stderr=log_stderr)
             programs.append(pconfig)
 
@@ -1229,7 +1232,7 @@ class ProcessConfig:
     def __init__(self, name, command, priority, autostart, autorestart,
                  startretrysecs, uid, logfile, logfile_backups,
                  logfile_maxbytes, stopsignal, stopwaitsecs, exitcodes,
-                 log_stderr):
+                 log_stdout, log_stderr):
         self.name = name
         self.command = command
         self.priority = priority
@@ -1243,6 +1246,7 @@ class ProcessConfig:
         self.stopsignal = stopsignal
         self.stopwaitsecs = stopwaitsecs
         self.exitcodes = exitcodes
+        self.log_stdout = log_stdout
         self.log_stderr = log_stderr
 
     def __cmp__(self, other):

+ 2 - 1
src/supervisor/supervisord.py

@@ -139,7 +139,8 @@ class Subprocess:
 
     def drain_stdout(self, *ignored):
         output = self.options.readfd(self.pipes['stdout'])
-        self.logbuffer += output
+        if self.config.log_stdout:
+            self.logbuffer += output
 
     def drain_stderr(self, *ignored):
         output = self.options.readfd(self.pipes['stderr'])

+ 2 - 1
src/supervisor/tests.py

@@ -2068,7 +2068,7 @@ class DummyPConfig:
     def __init__(self, name, command, priority=999, autostart=True,
                  autorestart=True, startretrysecs=10,
                  uid=None, logfile=None, logfile_backups=0,
-                 logfile_maxbytes=0, log_stderr=False,
+                 logfile_maxbytes=0, log_stdout=True, log_stderr=False,
                  stopsignal=signal.SIGTERM, stopwaitsecs=10,
                  exitcodes=[0,2]):
         self.name = name
@@ -2081,6 +2081,7 @@ class DummyPConfig:
         self.logfile = logfile
         self.logfile_backups = logfile_backups
         self.logfile_maxbytes = logfile_maxbytes
+        self.log_stdout = log_stdout
         self.log_stderr = log_stderr
         self.stopsignal = stopsignal
         self.stopwaitsecs = stopwaitsecs