Timestamping logs of programs managed by supervisord

Active3 hr before
Viewed126 times

4 Answers


Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers ,I'm using supervisord to manage a php program that needs to be running in the background. That program logs events out to a file worker_log. It is simple enough to configure this in the supervisord.conf I'm using:,When running this command manually it seems to work fine. However, supervisord seems to somehow prevent it from properly functioning, and I'm unable to tell how. worker.php performs fine, but it's reporting is, in this configuration, suppressed. And, because of that, it of course does not add the timestamp.,However, I'd like for the events being written to the log to timestamp themselves. I don't have control over the php program, so decorating it's log is not an option. I figured that what I would do is comment out the above logging configuration and decorate the program via command-line pipes in supervisor's command configuration:

You could write a dedicated wrapper script that will attach a filter to the stderr before invoking your worker code:

// filter to prepend date/time on all stderr output
class eventdata_filter extends php_user_filter {
   function filter($in, $out, & $consumed, $closing) {
      while (($bucket = stream_bucket_make_writeable($in))) {
         $bucket - > data = date('c').
         ' '.$bucket - > data;
         $consumed += $bucket - > datalen;
         stream_bucket_append($out, $bucket);
      return PSFS_PASS_ON;

// register our custom filter    
stream_filter_register('eventdata', 'eventdata_filter');

// keep a reference to the attached filter
$filter = stream_filter_append(STDERR, 'eventdata', STREAM_FILTER_WRITE);

// isolate the worker from any variables in this scope, such as $filter
function run() {
   include 'worker.php';

// run the worker

// remove the filter
load more v

Installing Supervisor Supervisor can be installed through two ways: ,By downloading the Supervisor package and invoking the command: apt-get install supervisor,systemctl status supervisord.service,sudo nano /etc/supervisor/supervisord.conf

To check what version of Python is installed on your system, type the command below:

load more v

Here is an example configuration file that mimics the default logging configuration of the Supervisor. It emits UTC timestamped message lines to standard output at the error level.,Users are encouraged to read the log4rs configuration documentation for further details.,The configuration scheme is essentially the same as that described in the documentation of the Rust env_logger crate, with the exception that we do not allow additional regular expression-based filtering. The configuration values the Supervisor recognizes are described below:,Supervisor Configuration File

# ALWAYS keep this key in the configuration;
removing it means changes
# to config won 't get picked up without a restart.
# Uses humantime to parse the duration;
# https: //docs.rs/humantime/1.2.0/humantime/fn.parse_duration.html
   refresh_rate: 5 seconds

   kind: console
   # See https: //docs.rs/log4rs/0.8.3/log4rs/#configuration for
   # formatting options
pattern: "[{d(%Y-%m-%dT%H:%M:%SZ)(utc)} {l} {module}] {message}{n}"

   level: error
load more v

Supervisor has been tested and is known to run on Linux (Ubuntu), Mac OS X (10.4, 10.5, 10.6), and Solaris (10 for Intel) and FreeBSD 6.1. It will likely work fine on most UNIX systems.,Fixed a bug where the stdout_syslog and stderr_syslog options of a [program:x] section could not be used unless file logging for the same program had also been configured. The file and syslog options can now be used independently. Patch by Scott Stroupe.,FastCGI programs ([fcgi-program:x] sections) can now be used in groups ([group:x]). Patch by Florian Apolloner.,Fixed a hang that could occur in supervisord if log rotation is used and an outside program deletes an active log file. Patch by Magnus Lycka.

When parsing “environment=” in the config file, changes introduced in 3.0a8 prevented Supervisor from parsing some characters commonly found in paths unless quoting was used as in this example:

environment = HOME = '/home/auser'

Supervisor once again allows the above line to be written as:

environment = HOME = /home/auser
load more v

Other "undefined-undefined" queries related to "Timestamping logs of programs managed by supervisord"