Skip to content

Append timestamp to stdout and stderr logs and config flags #469

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions supervisor/dispatchers.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,17 @@ def _setup_logging(self, config, channel):

maxbytes = getattr(config, '%s_logfile_maxbytes' % channel)
backups = getattr(config, '%s_logfile_backups' % channel)
fmt = '%(message)s'
if logfile == 'syslog':
append_timestamp = getattr(config,'%s_append_timestamp' % channel)
if append_timestamp:
fmt = '%(asctime)s: %(message)s'
else:
fmt = '%(message)s'

if logfile == 'syslog':
warnings.warn("Specifying 'syslog' for filename is deprecated. "
"Use %s_syslog instead." % channel, DeprecationWarning)
fmt = ' '.join((config.name, fmt))

self.mainlog = loggers.handle_file(
config.options.getLogger(),
filename=logfile,
Expand Down
8 changes: 7 additions & 1 deletion supervisor/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,10 @@ def get(section, opt, *args, **kwargs):
syslog = boolean(get(section, sy_key, False))
logfiles[sy_key] = syslog

append_ts_key = '%s_append_timestamp' % k
append_ts = boolean(get(section,append_ts_key,False))
logfiles[append_ts_key] = append_ts

if lf_val is Automatic and not maxbytes:
self.parse_warnings.append(
'For [%s], AUTO logging used for %s without '
Expand All @@ -942,12 +946,14 @@ def get(section, opt, *args, **kwargs):
startretries=startretries,
uid=uid,
stdout_logfile=logfiles['stdout_logfile'],
stdout_append_timestamp=logfiles['stdout_append_timestamp'],
stdout_capture_maxbytes = stdout_cmaxbytes,
stdout_events_enabled = stdout_events,
stdout_logfile_backups=logfiles['stdout_logfile_backups'],
stdout_logfile_maxbytes=logfiles['stdout_logfile_maxbytes'],
stdout_syslog=logfiles['stdout_syslog'],
stderr_logfile=logfiles['stderr_logfile'],
stderr_append_timestamp=logfiles['stderr_append_timestamp'],
stderr_capture_maxbytes = stderr_cmaxbytes,
stderr_events_enabled = stderr_events,
stderr_logfile_backups=logfiles['stderr_logfile_backups'],
Expand Down Expand Up @@ -1711,7 +1717,7 @@ class ProcessConfig(Config):
'stderr_events_enabled', 'stderr_syslog',
'stopsignal', 'stopwaitsecs', 'stopasgroup', 'killasgroup',
'exitcodes', 'redirect_stderr' ]
optional_param_names = [ 'environment', 'serverurl' ]
optional_param_names = [ 'environment', 'serverurl','stdout_append_timestamp','stderr_append_timestamp' ]

def __init__(self, options, **params):
self.options = options
Expand Down
2 changes: 2 additions & 0 deletions supervisor/skel/sample.conf
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,13 @@ serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL for a unix socket
;stdout_logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB)
;stdout_logfile_backups=10 ; # of stdout logfile backups (default 10)
;stdout_capture_maxbytes=1MB ; number of bytes in 'capturemode' (default 0)
;stdout_append_timestamp=true ; appends timestamp to stdout log file ( default false)
;stdout_events_enabled=false ; emit events on stdout writes (default false)
;stderr_logfile=/a/path ; stderr log path, NONE for none; default AUTO
;stderr_logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB)
;stderr_logfile_backups=10 ; # of stderr logfile backups (default 10)
;stderr_capture_maxbytes=1MB ; number of bytes in 'capturemode' (default 0)
;stderr_append_timestamp=true ; appends timestamp to stderr log file (default false)
;stderr_events_enabled=false ; emit events on stderr writes (default false)
;environment=A="1",B="2" ; process environment additions (def no adds)
;serverurl=AUTO ; override serverurl computation (childutils)
Expand Down
4 changes: 3 additions & 1 deletion supervisor/tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ def __init__(self, options, name, command, directory=None, umask=None,
stdout_events_enabled=False,
stdout_logfile_backups=0, stdout_logfile_maxbytes=0,
stderr_logfile=None, stderr_capture_maxbytes=0,
stderr_events_enabled=False,
stderr_events_enabled=False,stdout_append_timestamp=False,stderr_append_timestamp=False,
stderr_logfile_backups=0, stderr_logfile_maxbytes=0,
redirect_stderr=False,
stopsignal=None, stopwaitsecs=10, stopasgroup=False, killasgroup=False,
Expand All @@ -534,6 +534,8 @@ def __init__(self, options, name, command, directory=None, umask=None,
self.stderr_logfile_backups = stderr_logfile_backups
self.stderr_logfile_maxbytes = stderr_logfile_maxbytes
self.redirect_stderr = redirect_stderr
self.stdout_append_timestamp = stdout_append_timestamp
self.stderr_append_timestamp = stderr_append_timestamp
if stopsignal is None:
import signal
stopsignal = signal.SIGTERM
Expand Down
1 change: 1 addition & 0 deletions supervisor/tests/test_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,7 @@ def test_options(self):
self.assertEqual(proc1.startretries, 10)
self.assertEqual(proc1.uid, 0)
self.assertEqual(proc1.stdout_logfile, '/tmp/cat.log')
self.assertEqual(proc1.stdout_append_timestamp,False)
self.assertEqual(proc1.stopsignal, signal.SIGKILL)
self.assertEqual(proc1.stopwaitsecs, 5)
self.assertEqual(proc1.stopasgroup, False)
Expand Down