]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
man: use setlogmask in LogControl1 example
authorLuca Boccassi <bluca@debian.org>
Mon, 22 May 2023 15:25:50 +0000 (16:25 +0100)
committerLuca Boccassi <luca.boccassi@gmail.com>
Mon, 22 May 2023 17:05:29 +0000 (18:05 +0100)
Useful to show programs using syslog() how to easily set a mask.

man/logcontrol-example.c

index 734318da9327fd1d6a2c80802804d11e018f6cf5..c199ec7a0f2b1c33d57924c63f785d4052aae238 100644 (file)
@@ -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
    */