]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
main: add option to specify minimum log severity level
authorMiroslav Lichvar <mlichvar@redhat.com>
Thu, 4 Jul 2019 14:57:36 +0000 (16:57 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Thu, 4 Jul 2019 15:38:13 +0000 (17:38 +0200)
The -L option can be used to disable logging of less severe messages,
e.g informational or warnings.

doc/chronyd.adoc
main.c

index d3b78a41f2e3161d60ab3101e04e81f30070871e..d9574bc6adf2a43fc5335a089fe8b518549acd79 100644 (file)
@@ -70,6 +70,12 @@ print also debugging messages.
 This option specifies a file which should be used for logging instead of syslog
 or terminal.
 
+*-L* _level_::
+This option specifies the minimum severity level of messages to be written to
+the log file, syslog, or terminal. The following levels can be specified:
+0 (informational), 1 (warning), 2 (non-fatal error), and 3 (fatal error). The
+default value is 0.
+
 *-q*::
 When run in this mode, *chronyd* will set the system clock once and exit. It
 will not detach from the terminal.
diff --git a/main.c b/main.c
index 39ebf5d067480beca6b55a6af298ca2edcbdc105..bf0c7f7f388f87677ba26d56ef5b27f9258e53d1 100644 (file)
--- a/main.c
+++ b/main.c
@@ -406,7 +406,7 @@ int main
   int opt, debug = 0, nofork = 0, address_family = IPADDR_UNSPEC;
   int do_init_rtc = 0, restarted = 0, client_only = 0, timeout = 0;
   int scfilter_level = 0, lock_memory = 0, sched_priority = 0;
-  int clock_control = 1, system_log = 1;
+  int clock_control = 1, system_log = 1, log_severity = LOGS_INFO;
   int config_args = 0;
 
   do_platform_checks();
@@ -427,7 +427,7 @@ int main
   optind = 1;
 
   /* Parse short command-line options */
-  while ((opt = getopt(argc, argv, "46df:F:hl:mnP:qQrRst:u:vx")) != -1) {
+  while ((opt = getopt(argc, argv, "46df:F:hl:L:mnP:qQrRst:u:vx")) != -1) {
     switch (opt) {
       case '4':
       case '6':
@@ -447,6 +447,9 @@ int main
       case 'l':
         log_file = optarg;
         break;
+      case 'L':
+        log_severity = parse_int_arg(optarg);
+        break;
       case 'm':
         lock_memory = 1;
         break;
@@ -510,7 +513,7 @@ int main
     LOG_OpenSystemLog();
   }
   
-  LOG_SetMinSeverity(debug >= 2 ? LOGS_DEBUG : LOGS_INFO);
+  LOG_SetMinSeverity(debug >= 2 ? LOGS_DEBUG : log_severity);
   
   LOG(LOGS_INFO, "chronyd version %s starting (%s)", CHRONY_VERSION, CHRONYD_FEATURES);