]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#1150] Added %t in log patterns
authorFrancis Dupont <fdupont@isc.org>
Fri, 27 Mar 2020 16:09:35 +0000 (17:09 +0100)
committerFrancis Dupont <fdupont@isc.org>
Mon, 30 Mar 2020 16:51:31 +0000 (18:51 +0200)
doc/sphinx/arm/logging.rst
src/lib/log/output_option.cc
src/lib/log/tests/buffer_logger_test.sh.in
src/lib/log/tests/destination_test.sh.in
src/lib/log/tests/init_logger_test.sh.in
src/lib/log/tests/local_file_test.sh.in
src/lib/log/tests/logger_lock_test.sh.in
src/lib/log/tests/logger_manager_unittest.cc
src/lib/log/tests/severity_test.sh.in

index e310da1ec46b40117ec124ea9e997a8c49cd4180..9640627618f594d9db559dbc4495afa179f021ad 100644 (file)
@@ -636,13 +636,13 @@ below:
 
 ::
 
-    "%D{%Y-%m-%d %H:%M:%S.%q} %-5p [%c/%i] %m\n";
+    "%D{%Y-%m-%d %H:%M:%S.%q} %-5p [%c/%i/%t] %m\n";
 
 and a typical log produced by this pattern would look somethng like this:
 
 ::
 
-    2019-08-05 14:27:45.871 DEBUG [kea-dhcp4.dhcpsrv/8475] DHCPSRV_TIMERMGR_START_TIMER starting timer: reclaim-expired-leases
+    2019-08-05 14:27:45.871 DEBUG [kea-dhcp4.dhcpsrv/8475/12345] DHCPSRV_TIMERMGR_START_TIMER starting timer: reclaim-expired-leases
 
 That breaks down as like so:
 
@@ -665,6 +665,11 @@ That breaks down as like so:
 - %i
     The process ID. From the example log: ``8475``
 
+- %t
+    The thread ID. From the example log: ``12345``.
+    Note the format of the thread ID is OS dependent: e.g. on some systems
+    it is an address so is displayed in hexadecimal.
+
 - %m
     The log message itself. Keg log messages all begin with a message
     identifier followed by arbitrary log text. Every message in Kea has
@@ -699,7 +704,7 @@ The default for pattern for syslog output is as follows:
 
 ::
 
-    "%-5p [%c] %m\n";
+    "%-5p [%c/%t] %m\n";
 
 You can see that it omits the date and time as well the process ID as this
 information is typically output by syslog.  Note that Kea uses the pattern
index 459eb6b7b6ad21fbfc998d07c76053d72d38c654..4099ec123f17f522d10b65d68e83149925d0ac5d 100644 (file)
@@ -18,13 +18,13 @@ namespace isc {
 namespace log {
 
 /// Default layout pattern for console logs
-const std::string OutputOption::DEFAULT_CONSOLE_PATTERN = "%D{%Y-%m-%d %H:%M:%S.%q} %-5p [%c/%i] %m\n";
+const std::string OutputOption::DEFAULT_CONSOLE_PATTERN = "%D{%Y-%m-%d %H:%M:%S.%q} %-5p [%c/%i/%t] %m\n";
 
 /// Default layout pattern for file logs
-const std::string OutputOption::DEFAULT_FILE_PATTERN = "%D{%Y-%m-%d %H:%M:%S.%q} %-5p [%c/%i] %m\n";
+const std::string OutputOption::DEFAULT_FILE_PATTERN = "%D{%Y-%m-%d %H:%M:%S.%q} %-5p [%c/%i/%t] %m\n";
 
 /// Default layout pattern for syslog logs
-const std::string OutputOption::DEFAULT_SYSLOG_PATTERN = "%-5p [%c] %m\n";
+const std::string OutputOption::DEFAULT_SYSLOG_PATTERN = "%-5p [%c/%t] %m\n";
 
 OutputOption::Destination
 getDestination(const std::string& dest_str) {
index 8687225bb33d9163f7e833e06121187f18fde07a..976a26c04afb496c5af7f172844b4fdffbefbc8f 100644 (file)
@@ -1,5 +1,5 @@
 #!/bin/sh
-# Copyright (C) 2012-2016 Internet Systems Consortium, Inc. ("ISC")
+# Copyright (C) 2012-2020 Internet Systems Consortium, Inc. ("ISC")
 #
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -32,7 +32,7 @@ INFO  [buffertest.log] LOG_BAD_SEVERITY unrecognized log severity: info
 INFO  [buffertest.log] LOG_BAD_SEVERITY unrecognized log severity: info
 .
 ./buffer_logger_test 2>&1 | \
-    sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\]/[\1]/' | \
+    sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\/\(0x\)\{0,1\}\([0-9A-Fa-f]\{1,\}\)\]/[\1]/' | \
     cut -d' ' -f3- | diff $tempfile -
 passfail $?
 
index e79138a31682a35d56ca4c9ce5c62f8cefde925f..393027bc6bbfacf20e060eb2c5ceaa4afd7f9fcf 100644 (file)
@@ -1,5 +1,5 @@
 #!/bin/sh
-# Copyright (C) 2011-2016 Internet Systems Consortium, Inc. ("ISC")
+# Copyright (C) 2011-2020 Internet Systems Consortium, Inc. ("ISC")
 #
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -36,9 +36,11 @@ ERROR [example.beta] LOG_BAD_DESTINATION unrecognized log destination: beta_erro
 rm -f $destfile1 $destfile2
 ./logger_example -s error -f $destfile1_tmp -f $destfile2_tmp
 
-# strip the pids
-sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\]/[\1]/' < $destfile1_tmp > $destfile1
-sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\]/[\1]/' < $destfile2_tmp > $destfile2
+# strip the pids and thread ids
+sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\/\(0x\)\{0,1\}\([0-9A-Fa-f]\{1,\}\)\]/[\1]/' < $destfile1_tmp > $destfile1
+sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\/\(0x\)\{0,1\}\([0-9A-Fa-f]\{1,\}\)\]/[\1]/' < $destfile2_tmp > $destfile2
+# strip the thread ids
+
 
 echo -n  "   - destination 1:"
 cut -d' ' -f3- $destfile1 | diff $tempfile -
@@ -55,9 +57,9 @@ echo     "2. Two loggers, different destinations and severities"
 rm -f $destfile1 $destfile2
 ./logger_example -l example -s info -f $destfile1_tmp -l alpha -s warn -f $destfile2_tmp
 
-# strip the pids
-sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\]/[\1]/' < $destfile1_tmp > $destfile1
-sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\]/[\1]/' < $destfile2_tmp > $destfile2
+# strip the pids and thread ids
+sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\/\(0x\)\{0,1\}\([0-9A-Fa-f]\{1,\}\)\]/[\1]/' < $destfile1_tmp > $destfile1
+sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\/\(0x\)\{0,1\}\([0-9A-Fa-f]\{1,\}\)\]/[\1]/' < $destfile2_tmp > $destfile2
 
 # All output for example and example.beta should have gone to destfile1.
 # Output for example.alpha should have done to destfile2.
index 50530c873c2f9bd26b713f957f8571b339abc8d2..8ceb02d2878e79cb62c3fdbf77038fe755f1ef61 100644 (file)
@@ -1,5 +1,5 @@
 #!/bin/sh
-# Copyright (C) 2011-2016 Internet Systems Consortium, Inc. ("ISC")
+# Copyright (C) 2011-2020 Internet Systems Consortium, Inc. ("ISC")
 #
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -38,7 +38,7 @@ ERROR [kea.log] LOG_DUPLICATE_MESSAGE_ID duplicate message ID (error) in compile
 FATAL [kea.log] LOG_NO_MESSAGE_ID line fatal: message definition line found without a message ID
 .
 KEA_LOGGER_DESTINATION=stdout KEA_LOGGER_SEVERITY=DEBUG KEA_LOGGER_DBGLEVEL=99 ./init_logger_test | \
-    sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\]/[\1]/' | \
+    sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\/\(0x\)\{0,1\}\([0-9A-Fa-f]\{1,\}\)\]/[\1]/' | \
     cut -d' ' -f3- | diff $tempfile -
 passfail $?
 
@@ -52,7 +52,7 @@ ERROR [kea.log] LOG_DUPLICATE_MESSAGE_ID duplicate message ID (error) in compile
 FATAL [kea.log] LOG_NO_MESSAGE_ID line fatal: message definition line found without a message ID
 .
 KEA_LOGGER_DESTINATION=stdout KEA_LOGGER_SEVERITY=DEBUG KEA_LOGGER_DBGLEVEL=50 ./init_logger_test | \
-    sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\]/[\1]/' | \
+    sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\/\(0x\)\{0,1\}\([0-9A-Fa-f]\{1,\}\)\]/[\1]/' | \
     cut -d' ' -f3- | diff $tempfile -
 passfail $?
 
@@ -63,7 +63,7 @@ ERROR [kea.log] LOG_DUPLICATE_MESSAGE_ID duplicate message ID (error) in compile
 FATAL [kea.log] LOG_NO_MESSAGE_ID line fatal: message definition line found without a message ID
 .
 KEA_LOGGER_DESTINATION=stdout KEA_LOGGER_SEVERITY=WARN ./init_logger_test | \
-    sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\]/[\1]/' | \
+    sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\/\(0x\)\{0,1\}\([0-9A-Fa-f]\{1,\}\)\]/[\1]/' | \
     cut -d' ' -f3- | diff $tempfile -
 passfail $?
 
@@ -75,21 +75,21 @@ FATAL [kea.log] LOG_NO_MESSAGE_ID line fatal: message definition line found with
 .
 rm -f $destfile_tmp $destfile
 KEA_LOGGER_SEVERITY=FATAL KEA_LOGGER_DESTINATION=stdout ./init_logger_test 1> $destfile_tmp
-sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\]/[\1]/' < $destfile_tmp > $destfile
+sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\/\(0x\)\{0,1\}\([0-9A-Fa-f]\{1,\}\)\]/[\1]/' < $destfile_tmp > $destfile
 cut -d' ' -f3- $destfile | diff $tempfile -
 passfail $?
 
 echo -n  "   - stderr: "
 rm -f $destfile_tmp $destfile
 KEA_LOGGER_SEVERITY=FATAL KEA_LOGGER_DESTINATION=stderr ./init_logger_test 2> $destfile_tmp
-sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\]/[\1]/' < $destfile_tmp > $destfile
+sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\/\(0x\)\{0,1\}\([0-9A-Fa-f]\{1,\}\)\]/[\1]/' < $destfile_tmp > $destfile
 cut -d' ' -f3- $destfile | diff $tempfile -
 passfail $?
 
 echo -n  "   - file: "
 rm -f $destfile_tmp $destfile
 KEA_LOGGER_SEVERITY=FATAL KEA_LOGGER_DESTINATION=$destfile_tmp ./init_logger_test
-sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\]/[\1]/' < $destfile_tmp > $destfile
+sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\/\(0x\)\{0,1\}\([0-9A-Fa-f]\{1,\}\)\]/[\1]/' < $destfile_tmp > $destfile
 cut -d' ' -f3- $destfile | diff $tempfile -
 passfail $?
 
index fa4c449d85c830ff31a5fdf3b034ee5547944853..dd3035cf3dee96c3089b8047f7f33a25d0d5d5cf 100644 (file)
@@ -1,5 +1,5 @@
 #!/bin/sh
-# Copyright (C) 2011-2016 Internet Systems Consortium, Inc. ("ISC")
+# Copyright (C) 2011-2020 Internet Systems Consortium, Inc. ("ISC")
 #
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -44,7 +44,7 @@ ERROR [example.beta] LOG_BAD_DESTINATION unrecognized log destination: beta_erro
 WARN  [example.beta] LOG_BAD_STREAM bad log console output stream: beta_warn
 .
 ./logger_example -c stdout -s warn $localmes | \
-    sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\]/[\1]/' | \
+    sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\/\(0x\)\{0,1\}\([0-9A-Fa-f]\{1,\}\)\]/[\1]/' | \
     cut -d' ' -f3- | diff $tempfile -
 passfail $?
 
@@ -61,7 +61,7 @@ WARN  [example.beta] LOG_BAD_STREAM bad log console output stream: beta_warn
 .
 rm -f $localmes
 ./logger_example -c stdout -s warn $localmes | \
-    sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\]/[\1]/' | \
+    sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\/\(0x\)\{0,1\}\([0-9A-Fa-f]\{1,\}\)\]/[\1]/' | \
     cut -d' ' -f3- | diff $tempfile -
 passfail $?
 
index 1da24fe96b12b08a67d145f66dfed67526d8cc05..f25fd0741384eb198303614666b214a89e8d1733 100644 (file)
@@ -1,5 +1,5 @@
 #!/bin/sh
-# Copyright (C) 2012-2016 Internet Systems Consortium, Inc. ("ISC")
+# Copyright (C) 2012-2020 Internet Systems Consortium, Inc. ("ISC")
 #
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -30,7 +30,7 @@ LOGGER_LOCK_TEST: UNLOCK
 .
 rm -f $destfile
 KEA_LOGGER_SEVERITY=INFO KEA_LOGGER_DESTINATION=stdout ./logger_lock_test | \
-    sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\]/[\1]/' > $destfile
+    sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\/\(0x\)\{0,1\}\([0-9A-Fa-f]\{1,\}\)\]/[\1]/' > $destfile
 cut -d' ' -f3- $destfile | diff $tempfile -
 passfail $?
 
index 5f7ed9a0c9585bb383cd3a3fd573b8c655afd76f..516a2a17969435de9a2cbc0e8ef251f91fef0842 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2011-2017 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2011-2020 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -50,8 +50,6 @@ public:
     }
 };
 
-
-
 // Convenience class to create the specification for the logger "filelogger",
 // which, as the name suggests, logs to a file.  It remembers the file name and
 // deletes the file when instance of the class is destroyed.
@@ -134,7 +132,6 @@ private:
     string                  logname_;   // Name of this logger
 };
 
-
 // Convenience function to read an output log file and check that each line
 // contains the expected message ID
 //
@@ -392,8 +389,8 @@ TEST_F(LoggerManagerTest, checkLayoutPattern) {
                       "[[:digit:]]{2}:[[:digit:]]{2}:[[:digit:]]{2}\\.[[:digit:]]+[[:space:]]"
                       // %-5p
                       "[[:alpha:]]{1,5}[[:space:]]"
-                      // [%c/%i]
-                      "\\[[[:alnum:]\\-\\.]+/[[:digit:]]+\\][[:space:]]"
+                      // [%c/%i/%t]
+                      "\\[[[:alnum:]\\-\\.]+/[[:digit:]]+/(0x)?[[:xdigit:]]+\\][[:space:]]"
                       );
 
     const int re = regexec(*regex, line.c_str(), 0, NULL, 0);
index 762391df58dd0985c6ac1167829c20aee88f1729..2efe21db3989c809103d63c87c8757ee3b8043e3 100644 (file)
@@ -1,5 +1,5 @@
 #!/bin/sh
-# Copyright (C) 2011-2016 Internet Systems Consortium, Inc. ("ISC")
+# Copyright (C) 2011-2020 Internet Systems Consortium, Inc. ("ISC")
 #
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -36,7 +36,7 @@ WARN  [example.beta] LOG_BAD_STREAM bad log console output stream: beta_warn
 INFO  [example.beta] LOG_READ_ERROR error reading from message file beta: info
 .
 ./logger_example -c stdout | \
-    sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\]/[\1]/' | \
+    sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\/\(0x\)\{0,1\}\([0-9A-Fa-f]\{1,\}\)\]/[\1]/' | \
     cut -d' ' -f3- | diff $tempfile -
 passfail $?
 
@@ -48,7 +48,7 @@ FATAL [example.beta] LOG_BAD_SEVERITY unrecognized log severity: beta_fatal
 ERROR [example.beta] LOG_BAD_DESTINATION unrecognized log destination: beta_error
 .
 ./logger_example -c stdout -s error | \
-    sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\]/[\1]/' | \
+    sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\/\(0x\)\{0,1\}\([0-9A-Fa-f]\{1,\}\)\]/[\1]/' | \
     cut -d' ' -f3- | diff $tempfile -
 passfail $?
 
@@ -69,7 +69,7 @@ INFO  [example.beta] LOG_READ_ERROR error reading from message file beta: info
 DEBUG [example.beta] LOG_BAD_SEVERITY unrecognized log severity: beta/25
 .
 ./logger_example -c stdout -s debug -d 25 | \
-    sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\]/[\1]/' | \
+    sed -e 's/\[\([a-z0-9\.]\{1,\}\)\/\([0-9]\{1,\}\)\/\(0x\)\{0,1\}\([0-9A-Fa-f]\{1,\}\)\]/[\1]/' | \
     cut -d' ' -f3- | diff $tempfile -
 passfail $?