From 7b90003937bea5fd95ee1cfe3fa14d02ae304dd5 Mon Sep 17 00:00:00 2001
From: Daniel Salzman <daniel.salzman@nic.cz>
Date: Thu, 12 Jun 2014 16:16:03 +0200
Subject: [PATCH] log: make log severities cumulative

---
 doc/configuration.rst       | 10 ++++----
 doc/reference.rst           | 11 ++++-----
 samples/knot.full.conf      | 46 +++++++++++++++----------------------
 samples/knot.sample.conf.in | 12 ++++------
 src/knot/conf/cf-lex.l      | 20 ++++++++++------
 src/knot/conf/cf-parse.y    |  5 +++-
 6 files changed, 50 insertions(+), 54 deletions(-)

diff --git a/doc/configuration.rst b/doc/configuration.rst
index 60cdf2add0..ea342e4d17 100644
--- a/doc/configuration.rst
+++ b/doc/configuration.rst
@@ -23,7 +23,7 @@ which can be used as a base for your Knot DNS setup::
     }
 
     log {
-      syslog { any notice, warning, error; }
+      syslog { any info; }
     }
 
     zones {
@@ -40,10 +40,10 @@ Now let's go step by step through this minimal configuration file:
   on port 53 and second IPv6 called ``second_int`` also listening on
   port 53, which is the default port for the DNS. See :ref:`interfaces`.
 * The ``log`` statement defines the log facilities for Knot DNS.
-  In this example we told Knot DNS to send its log messages with the severities
-  ``debug``, ``warning`` and ``notice`` into the syslog.
-  If you omit this sections, all severities will printed to
-  either ``stdout`` or ``stderr``, and the severities
+  In this example we told Knot DNS to send its log messages with the severity
+  ``info`` or more serious to the syslog.
+  If you omit this sections, all severities will be printed
+  either to ``stdout`` or ``stderr``, and the severities
   from the ``warning`` and more serious to syslog. You can find all
   possible combinations in the :ref:`log`.
 * The ``zones`` statement is probably the most important one,
diff --git a/doc/reference.rst b/doc/reference.rst
index 294a5d1070..cff1ac6e0b 100644
--- a/doc/reference.rst
+++ b/doc/reference.rst
@@ -1063,10 +1063,10 @@ an error:
 
     log {
       [ log_name {
-        [ category severity [, severity ... ]; ]
+        [ category severity; ]
       } ]
       [ log_file filename {
-        [ category severity [, severity ... ]; ]
+        [ category severity; ]
       } ]
     }
 
@@ -1119,11 +1119,10 @@ Knot DNS has the following logging severities:
 * ``notice`` - Server notices and hints.
 * ``warning`` - Warnings that might require user action.
 * ``error`` - Recoverable error.  Action should be taken.
-* ``all`` - All severities.
+* ``critical`` - Non-recoverable error resulting in server shutdown.
 
-More severities may be listed for each category, but all severities
-have to be listed explicitly, i.e.  using ``warning`` severity does
-not mean that ``error`` severity messages will be logged as well.
+Each severity level includes all more serious levels, i.e. ``warning`` severity
+also includes ``error`` and ``critical`` severities.
 
 .. _log_file:
 
diff --git a/samples/knot.full.conf b/samples/knot.full.conf
index 1dedc33ebe..52c408e8b7 100644
--- a/samples/knot.full.conf
+++ b/samples/knot.full.conf
@@ -399,14 +399,13 @@ zones {
 #
 # Log messages are characterized by severity and category.
 # Supported severities:
-#   debug     - Debug messages. Must be turned on at compile time.
-#   info      - Informational messages.
-#   notice    - Notices and hints.
-#   warning   - Warnings. An action from the operator may be required.
-#   error     - Recoverable error. Some action should be taken.
+#   debug     - Debug messages and below. Must be turned on at compile time.
+#   info      - Informational messages and below.
+#   notice    - Notices and hints and below.
+#   warning   - Warnings and below. An action from the operator may be required.
+#   error     - Recoverable error and below. Some action should be taken.
 #   critical  - Non-recoverable errors resulting in server shutdown.
 #               (Not supported yet.)
-#   all       - All severities.
 #
 # Categories designate the source of the log message and roughly correspond
 #   to server modules
@@ -416,11 +415,6 @@ zones {
 #   answering - Messages regarding query processing and response creation.
 #   any       - All categories
 #
-# More severities (separated by commas) may be listed for each category.
-# All applicable severities must be listed.
-#   (I.e. specifying 'error' severity does mean: 'log error messages',
-#    and NOT 'log all messages of severity error and above'.)
-#
 # Default settings (in case there are no entries in 'log' section or the section
 # is missing at all):
 #
@@ -428,34 +422,32 @@ zones {
 # syslog { any error; }
 log {
 
-  # Log entry
-  #
   # Format 1:
   # <log> {
-  #   <category1> <severity1> [, <severity2> ...];
-  #   <category2> <severity1> [, <severity2> ...];
+  #   <category1> <severity1>;
+  #   <category2> <severity2>;
   #   ...
   # }
-  syslog {     # <log> is a symbolic name of a log device (see above)
-    # log errors of any category
-    any error;    # for <category> and <severity> see above
-    # log also warnings and notices from category 'zone'
-    zone warning, notice;
-    # log info from server
+
+  syslog {
+    # Log any error or critical to syslog
+    any error;
+    # Log all (excluding debug) from server to syslog
     server info;
   }
 
-  # Log fatal, warnings and errors to stderr
+  # Log any warning, error or critical to stderr
   stderr {
-    any error, warning;
+    any warning;
   }
 
   # Format 2:
-  # file <path> {
-  #   <category1> <severity1> [, <severity2> ...];
-  #   <category2> <severity1> [, <severity2> ...];
+  # file <path> { # <path> is absolute or relative path to log file
+  #   <category1> <severity1>;
+  #   <category2> <severity2>;
   # }
-  file "/tmp/knot-sample/knotd.debug" {  # <path> is absolute or relative path to log file
+
+  file "/tmp/knot-sample/knotd.debug" {
     server debug;
   }
 }
diff --git a/samples/knot.sample.conf.in b/samples/knot.sample.conf.in
index 956e8a9b1e..0fe02360a6 100644
--- a/samples/knot.sample.conf.in
+++ b/samples/knot.sample.conf.in
@@ -79,16 +79,12 @@ zones {
 
 log {
   syslog {
-    # log errors of any category
-    any error;    # for <category> and <severity> see above
-    # log also warnings and notices from category 'zone'
-    zone warning, notice;
-    # log info from server
-    server info;
+    # Log info and more serious events to syslog
+    any info;
   }
 
-  # Log fatal, warnings and errors to stderr
+  # Log warnings, errors and criticals to stderr
   stderr {
-    any error, warning;
+    any warning;
   }
 }
diff --git a/src/knot/conf/cf-lex.l b/src/knot/conf/cf-lex.l
index 4965f6239e..0bbeb88199 100644
--- a/src/knot/conf/cf-lex.l
+++ b/src/knot/conf/cf-lex.l
@@ -154,13 +154,19 @@ zone { lval.t = yytext; lval.i = LOG_ZONE; return LOG_SRC; }
 stdout { lval.t = yytext; lval.i = LOGT_STDOUT; return LOG_DEST; }
 stderr { lval.t = yytext; lval.i = LOGT_STDERR; return LOG_DEST; }
 syslog { lval.t = yytext; lval.i = LOGT_SYSLOG; return LOG_DEST; }
-all { lval.t = yytext; lval.i = LOG_UPTO(LOG_DEBUG); return LOG_LEVEL; }
-debug { lval.t = yytext; lval.i = LOG_MASK(LOG_DEBUG); return LOG_LEVEL; }
-info { lval.t = yytext; lval.i = LOG_MASK(LOG_INFO); return LOG_LEVEL; }
-notice { lval.t = yytext; lval.i = LOG_MASK(LOG_NOTICE); return LOG_LEVEL; }
-warning { lval.t = yytext; lval.i = LOG_MASK(LOG_WARNING); return LOG_LEVEL; }
-error { lval.t = yytext; lval.i = LOG_MASK(LOG_ERR); return LOG_LEVEL; }
-critical { lval.t = yytext; lval.i = LOG_MASK(LOG_CRIT); return LOG_LEVEL; }
+debug { lval.t = yytext; lval.i = LOG_UPTO(LOG_DEBUG); return LOG_LEVEL; }
+info { lval.t = yytext; lval.i = LOG_UPTO(LOG_INFO); return LOG_LEVEL; }
+notice { lval.t = yytext; lval.i = LOG_UPTO(LOG_NOTICE); return LOG_LEVEL; }
+warning { lval.t = yytext; lval.i = LOG_UPTO(LOG_WARNING); return LOG_LEVEL; }
+error { lval.t = yytext; lval.i = LOG_UPTO(LOG_ERR); return LOG_LEVEL; }
+critical { lval.t = yytext; lval.i = LOG_UPTO(LOG_CRIT); return LOG_LEVEL; }
+all {
+	lval.t = yytext;
+	lval.i = LOG_UPTO(LOG_DEBUG);
+	fprintf(stderr, "Warning: log severity 'all'' is deprecated. "
+	                "Use 'debug' or 'info' instead.\n");
+	return LOG_LEVEL;
+}
 
 increment|unixtime {
   lval.t = yytext;
diff --git a/src/knot/conf/cf-parse.y b/src/knot/conf/cf-parse.y
index fd70df4cfa..25012dd3c9 100644
--- a/src/knot/conf/cf-parse.y
+++ b/src/knot/conf/cf-parse.y
@@ -982,7 +982,10 @@ log_prios_start: {
 log_prios:
    log_prios_start
  | log_prios LOG_LEVEL ',' { this_logmap->prios |= $2.i; }
- | log_prios LOG_LEVEL ';' { this_logmap->prios |= $2.i; }
+ | log_prios LOG_LEVEL ';' { this_logmap->prios |= $2.i;
+	fprintf(stderr, "Warning: more log severities per statement is deprecated. "
+	                "Using the least serious one.\n");
+ }
  ;
 
 log_src:
-- 
GitLab