]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
logging: add configuration for future log cleaner
authorOleg Vasilev <oleg.vasilev@virtuozzo.com>
Mon, 30 Jan 2023 15:00:00 +0000 (21:00 +0600)
committerMartin Kletzander <mkletzan@redhat.com>
Mon, 6 Feb 2023 14:28:51 +0000 (15:28 +0100)
We want to specify the folder to clean and how much time can a log
chain live.

Signed-off-by: Oleg Vasilev <oleg.vasilev@virtuozzo.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
src/logging/log_daemon_config.c
src/logging/log_daemon_config.h
src/logging/test_virtlogd.aug.in
src/logging/virtlogd.aug
src/logging/virtlogd.conf

index 443674548854123aa40437f51bb066b3284a5381..248bd927d3f0aa7707324ccd24726adf48297ec8 100644 (file)
@@ -28,6 +28,7 @@
 #include "virutil.h"
 
 #define VIR_FROM_THIS VIR_FROM_CONF
+#define DEFAULT_LOG_ROOT LOCALSTATEDIR "/log/libvirt/"
 
 VIR_LOG_INIT("logging.log_daemon_config");
 
@@ -60,6 +61,7 @@ virLogDaemonConfigNew(bool privileged G_GNUC_UNUSED)
     data->admin_max_clients = 5000;
     data->max_size = 1024 * 1024 * 2;
     data->max_backups = 3;
+    data->max_age_days = 0;
 
     return data;
 }
@@ -72,6 +74,7 @@ virLogDaemonConfigFree(virLogDaemonConfig *data)
 
     g_free(data->log_filters);
     g_free(data->log_outputs);
+    g_free(data->log_root);
 
     g_free(data);
 }
@@ -94,6 +97,12 @@ virLogDaemonConfigLoadOptions(virLogDaemonConfig *data,
         return -1;
     if (virConfGetValueSizeT(conf, "max_backups", &data->max_backups) < 0)
         return -1;
+    if (virConfGetValueSizeT(conf, "max_age_days", &data->max_age_days) < 0)
+        return -1;
+    if (virConfGetValueString(conf, "log_root", &data->log_root) < 0)
+        return -1;
+    if (!data->log_root)
+        data->log_root = g_strdup(DEFAULT_LOG_ROOT);
 
     return 0;
 }
index 2ab0f67c96148646f3a80b6481015de00ecabcd9..43922feedf6ea980389a135a741e8b1d4413c922 100644 (file)
@@ -33,6 +33,9 @@ struct _virLogDaemonConfig {
 
     size_t max_backups;
     size_t max_size;
+
+    char *log_root;
+    size_t max_age_days;
 };
 
 
index cd5b0d91f8690f8c82d261fcac42d4ec11c9f818..8dfad39506081acf6ed9b96215e94b48810db749 100644 (file)
@@ -9,3 +9,5 @@ module Test_virtlogd =
         { "admin_max_clients" = "5" }
         { "max_size" = "2097152" }
         { "max_backups" = "3" }
+        { "max_age_days" = "0" }
+        { "log_root" = "/var/log/libvirt" }
index 0f1b290c728884420cacd22baabc97e8f1a9119b..bdf61dea6eb5752a1411cd631dc6f0ed6a93a801 100644 (file)
@@ -31,6 +31,8 @@ module Virtlogd =
                      | int_entry "admin_max_clients"
                      | int_entry "max_size"
                      | int_entry "max_backups"
+                     | int_entry "max_age_days"
+                     | str_entry "log_root"
 
    (* Each entry in the config is one of the following three ... *)
    let entry = logging_entry
index c53a1112bdb0110ac3e130989934916e16a981f5..5214e96121a17e6728644bc8a7e715d4f891bed0 100644 (file)
 # Maximum number of backup files to keep. Defaults to 3,
 # not including the primary active file
 #max_backups = 3
+
+# Maximum age for log files to live after the last modification.
+# Defaults to 0, which means "forever".
+#
+# WARNING: since virtlogd has no way to differentiate which files it used to
+# manage, the garbage collection mechanism will collect ALL files, once its age
+# reach max_age_days. Use only if you know what you mean.
+#max_age_days = 0
+
+# Root of all logs managed by virtlogd. Used to GC logs from obsolete machines.
+#
+# WARNING: all files under this location potentially can be GC-ed. See the
+# warning for max_age_days.
+#log_root = "/var/log/libvirt"