summaryrefslogtreecommitdiffstats
path: root/man/logcontrol-example.c
diff options
context:
space:
mode:
authorLuca Boccassi <bluca@debian.org>2023-05-22 17:25:50 +0200
committerLuca Boccassi <luca.boccassi@gmail.com>2023-05-22 19:05:29 +0200
commitfa63798a2e3f5ef568b6f191f6660cdd3b0be8fe (patch)
tree75e203bc77df19ab3b92ef783bdd1db30da8c243 /man/logcontrol-example.c
parentMerge pull request #27703 from keszybz/systemd-vconsole-ordering (diff)
downloadsystemd-fa63798a2e3f5ef568b6f191f6660cdd3b0be8fe.tar.xz
systemd-fa63798a2e3f5ef568b6f191f6660cdd3b0be8fe.zip
man: use setlogmask in LogControl1 example
Useful to show programs using syslog() how to easily set a mask.
Diffstat (limited to 'man/logcontrol-example.c')
-rw-r--r--man/logcontrol-example.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/man/logcontrol-example.c b/man/logcontrol-example.c
index 734318da93..c199ec7a0f 100644
--- a/man/logcontrol-example.c
+++ b/man/logcontrol-example.c
@@ -130,6 +130,7 @@ static int property_set(
for (int i = 0; i < LOG_DEBUG + 1; i++)
if (strcmp(value, log_level_table[i]) == 0) {
o->log_level = i;
+ setlogmask(LOG_UPTO(i));
return 0;
}
@@ -193,6 +194,12 @@ int main(int argc, char **argv) {
.syslog_identifier = "example",
};
+ /* https://man7.org/linux/man-pages/man3/setlogmask.3.html
+ * Programs using syslog() instead of sd_journal can use this API to cut logs
+ * emission at the source.
+ */
+ setlogmask(LOG_UPTO(o.log_level));
+
/* Acquire a connection to the bus, letting the library work out the details.
* https://www.freedesktop.org/software/systemd/man/sd_bus_default.html
*/