In case anyone else's interested, the patch attached makes supervisor
send child's stdout to syslog, if stdout_logfile is set to "syslog" in
the config.
However, there's another issue that prevents me from using supervisor:
when a process is stopped using
"supervisorctl stop" command, the last lines logged by the process are
lost. I think it's the same issue as reported here:
http://www.plope.com/software/collector/271
On Sat, Aug 14, 2010 at 1:17 AM, Denis Bilenko <[email protected]> wrote:
> Hi,
>
> What's the right way to redirect applications' stdout/stderr to syslog
> with supervisord?
>
> Usually (without supervisor), I do something like this:
> myapp 2>&1 | /usr/bin/logger -t myapp
>
> However, that does not seem to work properly with supervisord - if I
> exit supervisord, then myapp continues running.
>
> Do you use syslog with supervisord (with or without /usr/bin/logger)?
> If so, could you share the right config settings?
>
> Thanks,
> Denis.
>
diff -u pristine/supervisor-3.0a9/src/supervisor/dispatchers.py supervisor-3.0a9/src/supervisor/dispatchers.py
--- pristine/supervisor-3.0a9/src/supervisor/dispatchers.py 2010-05-13 03:35:32.000000000 +0700
+++ supervisor-3.0a9/src/supervisor/dispatchers.py 2010-08-14 15:27:48.288385784 +0700
@@ -100,10 +100,13 @@
if logfile:
maxbytes = getattr(process.config, '%s_logfile_maxbytes' % channel)
backups = getattr(process.config, '%s_logfile_backups' % channel)
+ frmt = '%(message)s'
+ if logfile == 'syslog':
+ frmt = '%s %s' % (process.config.name, frmt)
self.mainlog = process.config.options.getLogger(
logfile,
loggers.LevelsByName.INFO,
- '%(message)s',
+ frmt,
rotating=not not maxbytes, # optimization
maxbytes=maxbytes,
backups=backups)
diff -u pristine/supervisor-3.0a9/src/supervisor/loggers.py supervisor-3.0a9/src/supervisor/loggers.py
--- pristine/supervisor-3.0a9/src/supervisor/loggers.py 2010-05-13 03:35:32.000000000 +0700
+++ supervisor-3.0a9/src/supervisor/loggers.py 2010-08-14 15:28:06.408018529 +0700
@@ -228,6 +228,30 @@
os.rename(self.baseFilename, dfn)
self.stream = open(self.baseFilename, 'w')
+class SyslogHandler(Handler):
+
+ def __init__(self):
+ import syslog
+ self.syslog = syslog.syslog
+
+ def close(self):
+ pass
+
+ def emit(self, record):
+ try:
+ params = record.asdict()
+ message = params['message']
+ msgs = []
+ for line in message.rstrip('\n').split('\n'):
+ params['message'] = line
+ msg = self.fmt % params
+ try:
+ self.syslog(msg)
+ except UnicodeError:
+ self.syslog(msg.encode("UTF-8"))
+ except:
+ self.handleError(record)
+
class LogRecord:
def __init__(self, level, msg, **kw):
self.level = level
@@ -318,6 +342,9 @@
handlers.append(StreamHandler(io))
logger.getvalue = io.getvalue
+ elif filename == 'syslog':
+ handlers.append(SyslogHandler())
+
else:
if rotating is False:
handlers.append(FileHandler(filename))
Common subdirectories: pristine/supervisor-3.0a9/src/supervisor/medusa and supervisor-3.0a9/src/supervisor/medusa
Common subdirectories: pristine/supervisor-3.0a9/src/supervisor/scripts and supervisor-3.0a9/src/supervisor/scripts
Common subdirectories: pristine/supervisor-3.0a9/src/supervisor/skel and supervisor-3.0a9/src/supervisor/skel
Common subdirectories: pristine/supervisor-3.0a9/src/supervisor/tests and supervisor-3.0a9/src/supervisor/tests
Common subdirectories: pristine/supervisor-3.0a9/src/supervisor/ui and supervisor-3.0a9/src/supervisor/ui
_______________________________________________
Supervisor-users mailing list
[email protected]
http://lists.supervisord.org/mailman/listinfo/supervisor-users