summaryrefslogtreecommitdiffstats
path: root/src/basic/list.h
diff options
context:
space:
mode:
authorDaan De Meyer <daan.j.demeyer@gmail.com>2022-05-12 13:50:51 +0200
committerDaan De Meyer <daan.j.demeyer@gmail.com>2023-01-08 16:31:16 +0100
commit7c7a9138a20a6657071b3dd112fda9747ba1d6c1 (patch)
tree5ccfaa8ae2df0691badd2631a85f7866eb034b03 /src/basic/list.h
parentbasic: Add strv_extend_assignment() (diff)
downloadsystemd-7c7a9138a20a6657071b3dd112fda9747ba1d6c1.tar.xz
systemd-7c7a9138a20a6657071b3dd112fda9747ba1d6c1.zip
basic: Add log context
This commit adds support for attaching extra metadata to log messages written to the journal via log.h. We keep track of a thread local log context in log.c onto which we can push extra metadata fields that should be logged. Once a field is no longer relevant, it can be popped again from the log context. On top of this, we then add macros to allow pushing extra fields onto the log context. LOG_CONTEXT_PUSH() will push the provided field onto the log context and pop the last field from the log context when the current block ends. LOG_CONTEXT_PUSH_STRV() will do the same but for all fields in the given strv. Using the macros is as simple as putting them anywhere inside a block to add a field to all following log messages logged from inside that block. void myfunction(...) { ... LOG_CONTEXT_PUSH("MYMETADATA=abc"); // Every journal message logged will now have the MYMETADATA=abc // field included. } For convenience, there's also LOG_CONTEXT_PUSHF() to allow constructing the field to be logged using printf() syntax. log_context_new()/log_context_free() can be used to attach a log context to an async operation by storing it in the associated userdata struct.
Diffstat (limited to 'src/basic/list.h')
-rw-r--r--src/basic/list.h6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/basic/list.h b/src/basic/list.h
index 4a6e1505a5..ffc8bd8304 100644
--- a/src/basic/list.h
+++ b/src/basic/list.h
@@ -1,8 +1,6 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
-#include "macro.h"
-
/* The head of the linked list. Use this in the structure that shall
* contain the head of the linked list */
#define LIST_HEAD(t,name) \
@@ -190,3 +188,7 @@
LIST_REMOVE(name, *_a, _p); \
_p; \
})
+
+/* Now include "macro.h", because we want our definition of assert() which the macros above use. We include
+ * it down here instead of up top, since macro.h pulls in log.h which in turn needs our own definitions. */
+#include "macro.h"