diff options
author | Daan De Meyer <daan.j.demeyer@gmail.com> | 2023-03-27 16:55:17 +0200 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2023-03-29 13:00:33 +0900 |
commit | ee2975a9d9ae11e387f1c5af179e2e6b0ef6ada8 (patch) | |
tree | 812fb31f96dcaf612ea19f8e3b193fba7bbae91e /src/test/test-log.c | |
parent | 09ba6d1a14ba027f2bc4e3426c7dd85db19e720e (diff) | |
download | systemd-ee2975a9d9ae11e387f1c5af179e2e6b0ef6ada8.tar.gz |
log: Add LOG_SET_PREFIX() macro
LOG_SET_PREFIX() sets a logging prefix for the current block. The
prefix is prepended to every logging message in the block, followed
by ": ". If a logging prefix is already configured, it is overridden
for the duration of the block, after which it is restored.
A use case for this macro is when we're operating on an image or
directory (using --root or --image). We can use LOG_SET_PREFIX() to
prefix all logging messages with the directory or image that we're
operating on.
Diffstat (limited to 'src/test/test-log.c')
-rw-r--r-- | src/test/test-log.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/test/test-log.c b/src/test/test-log.c index 4fc4bc9087..e337a3c7df 100644 --- a/src/test/test-log.c +++ b/src/test/test-log.c @@ -175,6 +175,32 @@ static void test_log_context(void) { assert_se(log_context_num_fields() == 0); } +static void test_log_prefix(void) { + { + LOG_SET_PREFIX("ABC"); + + test_log_struct(); + test_long_lines(); + test_log_syntax(); + + { + LOG_SET_PREFIX("QED"); + + test_log_struct(); + test_long_lines(); + test_log_syntax(); + } + + test_log_struct(); + test_long_lines(); + test_log_syntax(); + } + + test_log_struct(); + test_long_lines(); + test_log_syntax(); +} + int main(int argc, char* argv[]) { test_file(); @@ -188,6 +214,7 @@ int main(int argc, char* argv[]) { test_long_lines(); test_log_syntax(); test_log_context(); + test_log_prefix(); } return 0; |