]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Automatically enable systemd journal logging
authorDaniel P. Berrange <berrange@redhat.com>
Thu, 27 Sep 2012 12:13:09 +0000 (13:13 +0100)
committerDaniel P. Berrange <berrange@redhat.com>
Fri, 28 Sep 2012 15:02:58 +0000 (16:02 +0100)
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).

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
daemon/libvirtd.c

index 1ca883afb2c9ce8e3b23d3090644b6cb878e64ed..b49acc5bde315173da2ab12bca617a90614dae0d 100644 (file)
@@ -636,7 +636,21 @@ daemonSetupLogging(struct daemonConfig *config,
         virLogParseOutputs(config->log_outputs);
 
     /*
-     * If no defined outputs, then direct to libvirtd.log when running
+     * If no defined outputs, then first try to direct it
+     * to the systemd journal (if it exists)....
+     */
+    if (virLogGetNbOutputs() == 0) {
+        char *tmp;
+        if (access("/run/systemd/journal/socket", W_OK) >= 0) {
+            if (virAsprintf(&tmp, "%d:journald", virLogGetDefaultPriority()) < 0)
+                goto no_memory;
+            virLogParseOutputs(tmp);
+            VIR_FREE(tmp);
+        }
+    }
+
+    /*
+     * otherwise direct to libvirtd.log when running
      * as daemon. Otherwise the default output is stderr.
      */
     if (virLogGetNbOutputs() == 0) {