log: Add key/value support to the log context

Now that we have reference counting, it's useful to be able to push
single key values onto the log context separately, so that we don't
have to allocate new storage to join the separate string together into
a single field which means we won't be able to reuse a context containing
the same field.
This commit is contained in:
Daan De Meyer
2023-03-21 14:54:04 +01:00
parent 883354532c
commit 81b3565efd
5 changed files with 75 additions and 20 deletions
+12 -1
View File
@@ -116,7 +116,7 @@ static void test_log_context(void) {
_cleanup_(log_context_unrefp) LogContext *ctx = NULL;
char **strv = STRV_MAKE("SIXTH=ijn", "SEVENTH=PRP");
assert_se(ctx = log_context_new(strv, /*owned=*/ false));
assert_se(ctx = log_context_new_strv(strv, /*owned=*/ false));
assert_se(log_context_num_contexts() == 1);
assert_se(log_context_num_fields() == 2);
@@ -160,6 +160,17 @@ static void test_log_context(void) {
test_log_syntax();
}
{
LOG_CONTEXT_PUSH_KEY_VALUE("ABC=", "QED");
LOG_CONTEXT_PUSH_KEY_VALUE("ABC=", "QED");
assert_se(log_context_num_contexts() == 1);
assert_se(log_context_num_fields() == 1);
test_log_struct();
test_long_lines();
test_log_syntax();
}
assert_se(log_context_num_contexts() == 0);
assert_se(log_context_num_fields() == 0);
}