unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Robert Vollmert <rob@vllmrt.net>
To: guix-devel@gnu.org
Subject: where to put helper to send stdout/stderr to syslog?
Date: Sun, 16 Jun 2019 14:22:14 +0200	[thread overview]
Message-ID: <C799D06C-679A-4333-BA08-FD77C6BF3E43@vllmrt.net> (raw)

Hi all,

I came up with the following wrapper that uses logger to redirect a
program’s console output to syslog:

(define* (logger-wrapper name exec . args)
  "Return a derivation that builds a script to start a process with
standard output and error redirected to syslog via logger."
  (define exp
    #~(begin
        (use-modules (ice-9 popen))
        (let* ((pid  (number->string (getpid)))
               (cmd  (string-append "logger -t " #$name " --id=" pid))
               (log  (open-output-pipe cmd)))
          (dup log 1)
          (dup log 2)
          (execl #$exec #$exec #$@args))))
  (program-file (string-append name "-logger") exp))

I use it as follows for a service that doesn’t support syslog:

(shepherd-service
  ...
  (start #~(make-forkexec-constructor
             '(#$(logger-wrapper “postgrest” (file-append postgrest “/bin/postgrest”)))
             …

Would logger-wrapper be generally useful to have available? If so,
is it named well, and where would it fit?

Cheers
Robert

             reply	other threads:[~2019-06-16 12:22 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-16 12:22 Robert Vollmert [this message]
2019-06-17 12:45 ` where to put helper to send stdout/stderr to syslog? Danny Milosavljevic
2019-06-17 13:12   ` Robert Vollmert
2019-06-17 14:45     ` Danny Milosavljevic
2019-06-18 13:32   ` Ludovic Courtès
2019-06-18 16:44     ` Robert Vollmert

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

  List information: https://guix.gnu.org/

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

  git send-email \
    --in-reply-to=C799D06C-679A-4333-BA08-FD77C6BF3E43@vllmrt.net \
    --to=rob@vllmrt.net \
    --cc=guix-devel@gnu.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.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).