[PATCH v2 3/5] logging: add configuration for future log cleaner

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



We want to specify the folder to clean and how much time can a log
chain live.

Signed-off-by: Oleg Vasilev <oleg.vasilev@xxxxxxxxxxxxx>
---
 src/logging/log_daemon_config.c  |  9 +++++++++
 src/logging/log_daemon_config.h  |  3 +++
 src/logging/test_virtlogd.aug.in |  2 ++
 src/logging/virtlogd.aug         |  2 ++
 src/logging/virtlogd.conf        | 14 ++++++++++++++
 5 files changed, 30 insertions(+)

diff --git a/src/logging/log_daemon_config.c b/src/logging/log_daemon_config.c
index 4436745488..248bd927d3 100644
--- a/src/logging/log_daemon_config.c
+++ b/src/logging/log_daemon_config.c
@@ -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;
 }
diff --git a/src/logging/log_daemon_config.h b/src/logging/log_daemon_config.h
index 2ab0f67c96..43922feedf 100644
--- a/src/logging/log_daemon_config.h
+++ b/src/logging/log_daemon_config.h
@@ -33,6 +33,9 @@ struct _virLogDaemonConfig {
 
     size_t max_backups;
     size_t max_size;
+
+    char *log_root;
+    size_t max_age_days;
 };
 
 
diff --git a/src/logging/test_virtlogd.aug.in b/src/logging/test_virtlogd.aug.in
index cd5b0d91f8..8dfad39506 100644
--- a/src/logging/test_virtlogd.aug.in
+++ b/src/logging/test_virtlogd.aug.in
@@ -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" }
diff --git a/src/logging/virtlogd.aug b/src/logging/virtlogd.aug
index 0f1b290c72..bdf61dea6e 100644
--- a/src/logging/virtlogd.aug
+++ b/src/logging/virtlogd.aug
@@ -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
diff --git a/src/logging/virtlogd.conf b/src/logging/virtlogd.conf
index c53a1112bd..5214e96121 100644
--- a/src/logging/virtlogd.conf
+++ b/src/logging/virtlogd.conf
@@ -101,3 +101,17 @@
 # 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"
-- 
2.38.1




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux