supervision - discussion about system services, daemon supervision, init, runlevel management, and tools such as s6 and runit
 help / color / mirror / Atom feed
From: "Laurent Bercot" <ska-supervision@skarnet.org>
To: "supervision@list.skarnet.org" <supervision@list.skarnet.org>
Subject: Re: ca catchall logger prefix log lines with service names?
Date: Tue, 25 Oct 2022 16:12:43 +0000	[thread overview]
Message-ID: <emf5ba3c7b-dadc-443e-84a5-db2d929e3182@a17662d2.com> (raw)
In-Reply-To: <20221025141920.rxxk6qkxpggloryt@localhost>

>I am trying to figure out if I can set up svscan catchall logger in such
>a way that it prepends a service name to every log line, so that it can
>be clear where the log came from.
>
>I am trying to avoid s6-rc setup where I need to explicitly create a
>matching logger service.

  You are saying "I want to use s6 without adopting s6 idioms because
I'm used to the way other supervisors do things, even when they're
giant hacks." :)

  It's much easier to have one dedicated set of logs per service, and
merge them later if that's what you want, than to have one big blob of
logs and separate them later for analysis. In other words: "cat | sort"
is cheaper than a series of "grep".

  The catch-all logger is exactly what it says: a catch-all. It only
gets the logs that are not diverted; it's not supposed to get
*everything* - although it can, if that's what you want, but then as
you noticed you get everything as is: output from the services go
directly to the catch-all logger. There is no intermediary process
that can prepend your log lines with information, because the services
have their output directly plugged into the pipe to the catch-all 
logger.

  The only way to modify the log lines is to insert an additional
process between your service and the catch-all logger that performs
the modification. And the simplest way to achieve that is to have
a foo/log service (or a foo-log consumer, if you're using s6-rc) for
every foo producer, that processes its stdin and writes the modified
lines to stdout, something like

   s6-format-filter "foo: %s"

  But that's still defining a consumer for your service. There is,
unfortunately, no way to do that without a consumer for every service.
And if you're going to add consumers anyway, you may as well write
dedicated loggers directly instead of line processors that send
everything back to the catch-all logger.

  Note that it's not s6 being difficult; it's s6 being out of the way
by default, by not touching your logs. If another supervisor allows
you to modify log lines by default, it means it's inserting itself
between the service and its logger, which is terribly inefficient.


>But creates a log file where all logs from all services are mixed up and
>are impossible to distinguish. There is already a strange looking thing
>prepended to every line (@400000006356da4b2cb3ba0a - a timestamp?)

  Yes, it's a TAI64N timestamp. Process the file through s6-tai64nlocal
to get human-readable timestamps. One of the advantages of TAI64N stamps
is that they're alphabetically sorted, so you can merge several log
files into one via "cat log1 log2 log3... | sort".

--
  Laurent


  reply	other threads:[~2022-10-25 16:12 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-25 14:19 Ihor Antonov
2022-10-25 16:12 ` Laurent Bercot [this message]
2022-10-25 16:23 ` Peter Shkenev

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=emf5ba3c7b-dadc-443e-84a5-db2d929e3182@a17662d2.com \
    --to=ska-supervision@skarnet.org \
    --cc=supervision@list.skarnet.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).