Re: set custom loglevel for external libraries

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

 



Thanks for your reply, I had no time to look at this until now.

Am Wed, 16 Jun 2021 11:44:10 +0100
schrieb Daniel P. Berrangé <berrange@xxxxxxxxxx>:

> Anyway if you used a virLogSource object, then turning on debugging
> exclusively for libxl library messages would be as simple as
> 
>   log_filters="1:libxl.libxl_library"
> 
> without affecting the global libvirt logging behaviour

It seems log_filters= does not allow arbitrary numbers.
virLogParseFilter would just allow values from 1 to 4.
Such extra logfilter needs to handle a xentoollog_level, values from 1 to 9 (>XTL_NONE and <XTL_NUM_LEVELS).

How should this be expressed in a config setting?

Perhaps just go the easy route and obtain a value from environment?

--- a/src/libxl/libxl_conf.c
+++ b/src/libxl/libxl_conf.c
@@ -1829,7 +1829,7 @@ libxlDriverConfigInit(libxlDriverConfig *cfg)
         return -1;
     }
 
-    cfg->logger = libxlLoggerNew(cfg->logDir, virLogGetDefaultPriority());
+    cfg->logger = libxlLoggerNew(cfg->logDir);
     if (!cfg->logger) {
         VIR_ERROR(_("cannot create logger for libxenlight, disabling driver"));
         return -1;
--- a/src/libxl/libxl_logger.c
+++ b/src/libxl/libxl_logger.c
@@ -129,25 +129,33 @@ libvirt_destroy(xentoollog_logger *logger_in)
 
 
 libxlLogger *
-libxlLoggerNew(const char *logDir, virLogPriority minLevel)
+libxlLoggerNew(const char *logDir)
 {
     xentoollog_logger_libvirt logger;
     g_autofree char *path = NULL;
-
-    switch (minLevel) {
-    case VIR_LOG_DEBUG:
-        logger.minLevel = XTL_DEBUG;
-        break;
-    case VIR_LOG_INFO:
-        logger.minLevel = XTL_INFO;
-        break;
-    case VIR_LOG_WARN:
-        logger.minLevel = XTL_WARN;
-        break;
-    case VIR_LOG_ERROR:
-        logger.minLevel = XTL_ERROR;
-        break;
+    char *xenlight_minlevel = getenv("xenlight_minlevel");
+    int minlevel;
+
+    if (!(xenlight_minlevel && *xenlight_minlevel &&
+        virStrToLong_i(xenlight_minlevel, NULL, 10, &minlevel) >= 0 &&
+        minlevel > XTL_NONE && minlevel < XTL_NUM_LEVELS)) {
+        minlevel = virLogGetDefaultPriority();
+        switch (minlevel) {
+        case VIR_LOG_DEBUG:
+            minlevel = XTL_DEBUG;
+            break;
+        case VIR_LOG_INFO:
+            minlevel = XTL_INFO;
+            break;
+        case VIR_LOG_WARN:
+            minlevel = XTL_WARN;
+            break;
+        case VIR_LOG_ERROR:
+            minlevel = XTL_ERROR;
+            break;
+        }
     }
+    logger.minLevel = minlevel;
     logger.logDir = logDir;
 
     if ((logger.files = virHashNew(libxlLoggerFileFree)) == NULL)
--- a/src/libxl/libxl_logger.h
+++ b/src/libxl/libxl_logger.h
@@ -24,8 +24,7 @@
 
 typedef struct xentoollog_logger_libvirt libxlLogger;
 
-libxlLogger *libxlLoggerNew(const char *logDir,
-                              virLogPriority minLevel);
+libxlLogger *libxlLoggerNew(const char *logDir);
 void libxlLoggerFree(libxlLogger *logger);
 
 void libxlLoggerOpenFile(libxlLogger *logger, int id, const char *name,


Olaf

Attachment: pgpchB54Oz_sx.pgp
Description: Digitale Signatur von OpenPGP


[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