Skip to main content
Topic: alternatives to runit log process (Read 382 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

alternatives to runit log process

I dislike the standard runit logging for some reasons.

1) it doesn't seem to separate stdout/stderr

2) the outputs are hidden in sub-folders of /var/log which can hinder searches

3) it splits off the logging process into another run/finish etc etc

I tried a few experiments to allow direct logging in the original run script. Here is an example which splits stdout / stderr into
different destinations. The comment at line 2 shows how logger could be used to provide standard kernel type logging.

Logger doesn't seem to allow a specific filename to be used.

To do that the code line 3 to the redirect exec shows how a bash script can be used to filter stdout/stderr to different files in /var/log.

The trap and sed use is based on https://unix.stackexchange.com/questions/440426/how-to-prefix-any-output-in-a-bash-script

Code: [Select]
#!/bin/bash
#exec  > >(logger -t'TLOG #####') 2> >(logger -t'TLOG !!!!!')
filt(){
    while read line; do
        d="$(TZ=UTC date +'%Y-%m-%d %H:%M:%S')"
        echo "$line" | sed -e's/^/'"$d"' /'
    done
}
exec    > >(trap "" INT TERM EXIT;  filt >> /var/log/tlog.log)  \
        2> >(trap "" INT TERM EXIT;  filt >> /var/log/tlog-error.log)

echo "############### TLOG start"
echo "############### TLOG start" 1>&2

for i in 1 2 3 4 5; do
    sleep 20
    echo "this is message $i to stdout"
    echo "this is message $i to stderr" 1>&2
done
pause


Re: alternatives to runit log process

Reply #1
I guess there are some misunderstandings to clarify.

First, about the runit logging system: obviously it doesn't separate stdout and stderr since the logging services only read from the stdout of the service in there stdin.

Quote from: runsv(8)
If  the directory service/log exists, runsv creates a pipe, redirects service/run's and service/finish's standard output to the pipe, switches to the directory service/log and starts ./run (and ./finish) exactly as described above for the service directory.  The standard input of the log service is redirected to read from the pipe.

Second, about logger: it is just meant to send stuff to the syslog facility of your choice, handling of this stuff is meant to be done using your syslog implementation (rsyslog, syslog-ng, ...). If you just want to send stuff in a file use stream redirections.

On another note you both complain that it splits logs and that it doesn't, just make a choice at some point.
For the fact it is hard to search logs in split directories, how is it harder that searching in a file with all logs mixed? Just use a recursive grep when you want to search in all the files simultaneously.

Re: alternatives to runit log process

Reply #2
Not sure why you are being so defensive.
 I meant no attack on runit or use of svlogd etc etc.
The illustrative run file is meant as a demonstration of what is possible, not as a recommendation.
I find it better to use a single directory of log files for searching and use logrotate. It's just a preference.
Splitting errors from info messages is a standard for some servers eg nginx; it's not required to do the split.
I know perfectly well what logger is for; again it's an alternative way to do logging.
If anything the ability of the runit init system to be so adaptable is what makes it so useful.