]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
log: introduce CGROUP_LOG_CONT level for logging
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Tue, 23 Aug 2022 17:21:47 +0000 (11:21 -0600)
committerTom Hromatka <tom.hromatka@oracle.com>
Tue, 23 Aug 2022 17:21:54 +0000 (11:21 -0600)
There are cases, where we might want to print a very long/multiline log
message to the user. We could call the cgroup_log(), multiple times to
fit the log message, but the downside is that every time the
cgroup_log() called, the log level is prefixed to the message, hence
introducing loglevel char string in the mid of the log message.
For example, calling the cgroup_warn() twice to print a long warning:

cgroup_warn("cgroup v1 expects /proc/cgroup, check if ");
cgroup_warn("/proc mounted with subset=pid option\n");

output:
-------
$ sudo CGROUP_LOGLEVEL=DEBUG ./src/tools/cgget -g cpu:user.slice
...
Warning: cgroup v1 expects /proc/cgroup, check if Warning: /proc mounted
with subset=pid option

Introduce a new logging level, CGROUP_LOG_CONT and cgroup_cont() macro,
that will continue printing the log message, when loglevel is set to other
than default log level. The above code can be rewritten as:

cgroup_warn("cgroup v1 expects/proc/cgroup, check if ");
cgroup_cont("/proc mounted with subset=pid option\n");

output:
-------
$ sudo CGROUP_LOGLEVEL=DEBUG ./src/tools/cgget -g cpu:user.slice
...
Warning: cgroup v1 expects /proc/cgroup, check if /proc mounted with
subset=pid option

Also, make comsetic changes to cgroup_*().

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
include/libcgroup/log.h
src/libcgroup-internal.h

index 60e6fe3cf9f4d5542246c0779f2fde337922be6f..b65b8d39aa477d6777ef9e1d66c00b58ff94f103 100644 (file)
@@ -71,11 +71,16 @@ extern "C" {
  * Level of importance of a log message.
  */
 enum cgroup_log_level {
+       /**
+        * Continue printing the log message, with the previous log level.
+        * Used to print log messages without the line break.
+        */
+       CGROUP_LOG_CONT = 0,
        /**
         * Something serious happened and libcgroup failed to perform requested
         * operation.
         */
-       CGROUP_LOG_ERROR = 1,
+       CGROUP_LOG_ERROR,
        /**
         * Something bad happened but libcgroup recovered from the error.
         */
index 3ffb620c28845cf231de18570b5f5ec265ac5c4a..cf1fdc944fc18e99e5ee3cf301f814a51fcac5c9 100644 (file)
@@ -70,10 +70,11 @@ extern "C" {
 
 #define CGROUP_FILE_PREFIX     "cgroup"
 
-#define cgroup_err(x...) cgroup_log(CGROUP_LOG_ERROR, "Error: " x)
-#define cgroup_warn(x...) cgroup_log(CGROUP_LOG_WARNING, "Warning: " x)
-#define cgroup_info(x...) cgroup_log(CGROUP_LOG_INFO, "Info: " x)
-#define cgroup_dbg(x...) cgroup_log(CGROUP_LOG_DEBUG, x)
+#define cgroup_err(x...)       cgroup_log(CGROUP_LOG_ERROR, "Error: " x)
+#define cgroup_warn(x...)      cgroup_log(CGROUP_LOG_WARNING, "Warning: " x)
+#define cgroup_info(x...)      cgroup_log(CGROUP_LOG_INFO, "Info: " x)
+#define cgroup_dbg(x...)       cgroup_log(CGROUP_LOG_DEBUG, x)
+#define cgroup_cont(x...)      cgroup_log(CGROUP_LOG_CONT, x)
 
 #define CGROUP_DEFAULT_LOGLEVEL CGROUP_LOG_ERROR