Re: Logging in a web server context

From: Jan Braun <>
Date: Sat, 13 Jun 2020 12:59:42 +0200


Carl Winbäck schrob:
> Is it possible when using s6-svscan/s6-supervise to somehow arrange so
> that a daemon’s stdout is sent to one logdir and stderr to another
> logdir?

I'm not completely sure about s6, but runsv (from runit) hands only the
stdout of the ./run script to the logger, and passes the stderr out of
it's own stderr. This allows you to nest two runsv instances, one for
each output channel:

$ find -type f | xargs head -n 99
==> ./inner/log/run <==
mkdir -p stdout
svlogd -t stdout

==> ./inner/run <==
echo stderr >&2
echo stdout
sleep 10

==> ./log/run <==
mkdir -p stderr
svlogd -t stderr

==> ./run <==
exec runsv inner 2>&1
$ timeout 11 runsv .
$ find -name current | xargs head
==> ./inner/log/stdout/current <==
_at_400000005ee4a23f2591745c stdout
_at_400000005ee4a24925b79614 stdout

==> ./log/stderr/current <==
_at_400000005ee4a23f257ae304 stderr
_at_400000005ee4a24925b76f04 stderr

Translation to s6 is left as an exercise to the reader.

> One tricky aspect of logging that is specific to web servers is that
> they emit two different categories of messages:
> a) Errors and warnings
> b) Info about page requests[2]

You could also run the webserver with stderr redirected to stdout, and
let s6-log/svlogd filter the messages into one of two logdirs:

$ printf 'stdout\nstderr\n' | s6-log -- '-.*err' t ./stdout f t ./stderr
$ head std*/current
==> stderr/current <==
_at_400000005ee4acd00efdfbe9 stderr

==> stdout/current <==
_at_400000005ee4acd00efd6f5e stdout

However, that's a brittle solution, because it relies on you creating
correctly-matching filter rules. Depending on the webserver's output, it
might still be feasible, but I recommend the other approach.

HTH & cheers,

Received on Sat Jun 13 2020 - 10:59:42 UTC

This archive was generated by hypermail 2.3.0 : Sun May 09 2021 - 19:44:19 UTC