Prepending log lines with custom tag

From: Robin Roestenburg <robin_at_roestenburg.io>
Date: Wed, 21 Sep 2016 11:06:51 +0200

I am running s6 inside my Docker containers using the s6-overlay
project.

The logs of the services inside my containers are processed by s6-log. I
have configured the logging script to write to both stdout and a
directory. By routing the logs to stdout they are processed by the
logging driver configured in the Docker daemon. This driver sends the
logs to some centralized logging solution. By configuring the log format
of a service to include a tag, say `[nginx]`, I am able to filter the
logs of that service in the centralized logging solution.

This works for most services, but for some it is not possible to change
the log format. For these services, I would like to prepend the tag to
the log before it is processed by s6-log.

This is a simple version of a log script I am using:

#!/usr/bin/execlineb -PW

s6-envdir /var/run/s6/container_environment
importas -is S6_LOGGING_SCRIPT S6_LOGGING_SCRIPT

redirfd -rnb 0 /var/run/itrp/foo-log-fifo
s6-log -bp -- ${S6_LOGGING_SCRIPT} /var/log/foo


In my mind I would need to:
- process the output from the fifo by prepending a tag,
- move the processed output to stdin where s6-log can pick it up
But I am not sure how to do this.

Any suggestions?

-- 
Robin Roestenburg
Received on Wed Sep 21 2016 - 09:06:51 UTC

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