daemon: Fix LIBVIRT_DEBUG=1 default output

This commit changes the behavior of LIBVIRT_DEBUG=1 libvirtd:

$ git show 7022b09111
commit 7022b09111
Author: Daniel P. Berrange <berrange@redhat.com>
Date:   Thu Sep 27 13:13:09 2012 +0100

    Automatically enable systemd journal logging

    Probe to see if the systemd journal is accessible, and if
    so enable logging to the journal by default, rather than
    stderr (current default under systemd).

Previously  'LIBVIRT_DEBUG=1 /usr/sbin/libvirtd' would show all debug
output to stderr, now it send debug output to the journal.

Only use the journal by default if running in daemon mode, or
if stdin is _not_ a tty. This should make libvirtd launched from
systemd use the journal, but preserve the old behavior in most
situations.
This commit is contained in:
Cole Robinson 2012-10-24 16:51:44 -04:00
parent d8aae15aa1
commit eba36a3878
2 changed files with 8 additions and 3 deletions

View File

@ -636,10 +636,13 @@ daemonSetupLogging(struct daemonConfig *config,
virLogParseOutputs(config->log_outputs);
/*
* If no defined outputs, then first try to direct it
* to the systemd journal (if it exists)....
* If no defined outputs, and either running
* as daemon or not on a tty, then first try
* to direct it to the systemd journal
* (if it exists)....
*/
if (virLogGetNbOutputs() == 0) {
if (virLogGetNbOutputs() == 0 &&
(godaemon || !isatty(STDIN_FILENO))) {
char *tmp;
if (access("/run/systemd/journal/socket", W_OK) >= 0) {
if (virAsprintf(&tmp, "%d:journald", virLogGetDefaultPriority()) < 0)

View File

@ -1247,6 +1247,8 @@ virLogParseOutputs(const char *outputs)
if (cur == NULL)
return -1;
VIR_DEBUG("outputs=%s", outputs);
virSkipSpaces(&cur);
while (*cur != 0) {
prio= virParseNumber(&cur);