]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[3591] Default logging refactored.
authorTomek Mrugalski <tomasz@isc.org>
Fri, 12 Sep 2014 15:20:47 +0000 (17:20 +0200)
committerTomek Mrugalski <tomasz@isc.org>
Fri, 12 Sep 2014 15:20:47 +0000 (17:20 +0200)
14 files changed:
Makefile.am
src/bin/d2/tests/Makefile.am
src/bin/dhcp4/tests/Makefile.am
src/bin/dhcp6/tests/Makefile.am
src/bin/keactrl/tests/Makefile.am
src/lib/dhcpsrv/daemon.cc
src/lib/dhcpsrv/logging.cc
src/lib/log/interprocess/Makefile.am
src/lib/log/logger_support.h
src/lib/log/logger_unittest_support.cc
src/lib/log/logger_unittest_support.h
src/lib/log/tests/logger_level_impl_unittest.cc
src/lib/log/tests/logger_level_unittest.cc
src/lib/log/tests/logger_support_unittest.cc

index 25dd138bef54495b83c66298a4ef104c49354a21..887e3b5860400f8e52866a63364a8fdb92512951 100644 (file)
@@ -119,6 +119,10 @@ cppcheck:
                --template '{file}:{line}: check_fail: {message} ({severity},{id})' \
                src
 
+# These steps are necessary during installation
+install-exec-hook:
+       mkdir -p ${localstatedir}/run/${PACKAGE_NAME}
+
 ### include tool to generate documentation from log message specifications
 ### in the distributed tarball:
 EXTRA_DIST = tools/system_messages.py
index 98f987cbba2f852031318a5db9fdbeb123f9be8d..e518fe9fb92497cdc519b4c269fa005d309c491c 100644 (file)
@@ -14,7 +14,7 @@ EXTRA_DIST += testdata/d2_cfg_tests.json
 check-local:
        for shtest in $(SHTESTS) ; do \
        echo Running test: $$shtest ; \
-       export B10_LOCKFILE_DIR_FROM_BUILD=$(abs_top_builddir); \
+       export KEA_LOCKFILE_DIR=$(abs_top_builddir); \
        ${SHELL} $(abs_builddir)/$$shtest || exit ; \
        done
 
index 727753b80605e12e4d77cf85837807f7e2ce224d..2c7bf627c819b89c5c99a09a6cdb50114679884d 100644 (file)
@@ -13,7 +13,7 @@ EXTRA_DIST  = dhcp4_process_tests.sh.in
 check-local:
        for shtest in $(SHTESTS) ; do \
        echo Running test: $$shtest ; \
-       export B10_LOCKFILE_DIR_FROM_BUILD=$(abs_top_builddir); \
+       export KEA_LOCKFILE_DIR=$(abs_top_builddir); \
        ${SHELL} $(abs_builddir)/$$shtest || exit ; \
        done
 
index b54b9e9948f0abce577fbfe5af255979befee871..c530f3c9ff86816bdaec66c4a2b17437023daf6f 100644 (file)
@@ -13,7 +13,7 @@ EXTRA_DIST = $(SHTESTS) dhcp6_process_tests.sh.in
 check-local:
        for shtest in $(SHTESTS) ; do \
        echo Running test: $$shtest ; \
-       export B10_LOCKFILE_DIR_FROM_BUILD=$(abs_top_builddir); \
+       export KEA_LOCKFILE_DIR=$(abs_top_builddir); \
        ${SHELL} $(abs_builddir)/$$shtest || exit ; \
        done
 
index 7ff0952cf99fe928753c7222ef396f517f4860ea..b692cbe41a58aa1352592ee875e9e7587ed156cd 100644 (file)
@@ -14,6 +14,7 @@ check-local:
        for shtest in $(SHTESTS) ; do \
        echo Running test: $$shtest ; \
        chmod +x $(abs_builddir)/$$shtest ; \
+       export KEA_LOCKFILE_DIR=$(abs_top_builddir); \
        export KEACTRL_BUILD_DIR=$(abs_top_builddir); \
        export KEACTRL_CONF=$(abs_top_builddir)/src/bin/keactrl/tests/keactrl_test.conf; \
        ${SHELL} $(abs_builddir)/$$shtest || exit ; \
index fdf4bce1bd16095eda8d70a6ab5c86a41a039c72..6922b276c96fc1217b345f60a0efa5df88ab9193 100644 (file)
@@ -94,13 +94,10 @@ void Daemon::configureLogger(const isc::data::ConstElementPtr& log_config,
     parser.applyConfiguration();
 }
 
-void Daemon::loggerInit(const char*, bool verbose) {
-
-    setenv("KEA_LOCKFILE_DIR", "/tmp", 0);
+void Daemon::loggerInit(const char* name, bool verbose) {
 
     // Initialize logger system
-    isc::log::initLogger(isc::log::getDefaultRootLoggerName().c_str(),
-                         isc::log::DEBUG, isc::log::MAX_DEBUG_LEVEL,
+    isc::log::initLogger(name, isc::log::DEBUG, isc::log::MAX_DEBUG_LEVEL,
                          NULL);
 
     // Apply default configuration (log INFO or DEBUG to stdout)
index 27ec41dfc35d834c7ba02d5c83284608e2dd1322..0a5a8b5f544f288d23d8b06f3738f6c5c7202d9a 100644 (file)
@@ -17,6 +17,7 @@
 #include <boost/foreach.hpp>
 #include <boost/lexical_cast.hpp>
 #include <log/logger_specification.h>
+#include <log/logger_support.h>
 #include <log/logger_manager.h>
 #include <log/logger_name.h>
 
@@ -216,17 +217,11 @@ void LogConfigParser::applyConfiguration() {
 }
 
 void LogConfigParser::applyDefaultConfiguration(bool verbose) {
-    LoggerSpecification spec("kea", (verbose?isc::log::DEBUG : isc::log::INFO),
+    LoggerSpecification spec(isc::log::getRootLoggerName(),
+                             (verbose?isc::log::DEBUG : isc::log::INFO),
                              (verbose?99:0));
 
-    OutputOption option;
-    option.destination = OutputOption::DEST_CONSOLE;
-    option.stream = OutputOption::STR_STDOUT;
-
-    spec.addOutputOption(option);
-
-    LoggerManager manager;
-    manager.process(spec);
+    setDefaultLoggingOutput(verbose);
 }
 
 } // namespace isc::dhcp
index 4becc0d9a1a0f4ace3269fc2f6a2ed9fc1434653..2e949d16b8e68d75169ac988b110d4e0a43b10fe 100644 (file)
@@ -1,7 +1,7 @@
 SUBDIRS = . tests
 
 AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib
-AM_CPPFLAGS += -DLOCKFILE_DIR=\"${localstatedir}/${PACKAGE_NAME}\"
+AM_CPPFLAGS += -DLOCKFILE_DIR=\"${localstatedir}/run/${PACKAGE_NAME}\"
 AM_CPPFLAGS += $(BOOST_INCLUDES)
 
 AM_CXXFLAGS = $(KEA_CXXFLAGS)
index bd3b5b3d62326ebd188a358a8630b019e6104e06..6caa61beb2bee88c39b5b90bf5addaf525574597 100644 (file)
@@ -69,6 +69,17 @@ void initLogger(const std::string& root,
                 int dbglevel = 0, const char* file = NULL,
                 bool buffer = false);
 
+/// \brief Reset root logger characteristics
+///
+/// This is a simplified interface into the resetting of the characteristics
+/// of the root logger.  It is aimed for use in unit tests and initial
+/// phase of bring up before logging configuration is parsed and applied.
+/// It uses KEA_LOGGER_DESTINATION environment variable to specify
+/// logging destination.
+/// @param verbose defines whether logging should be verbose or not
+void setDefaultLoggingOutput(bool verbose = true);
+
+
 } // namespace log
 } // namespace isc
 
index 539f05118dda6e3774fdf993a0e5ec491b6402f6..9c4d601f5ac81ffac96add117dea55aedd253fb9 100644 (file)
@@ -80,7 +80,7 @@ keaLoggerDbglevel(int defdbglevel) {
 // variables KEA_LOGGER_SEVERITY, KEA_LOGGER_DBGLEVEL and KEA_LOGGER_DESTINATION.
 
 void
-resetUnitTestRootLogger() {
+setDefaultLoggingOutput(bool verbose) {
 
     using namespace isc::log;
 
@@ -101,7 +101,8 @@ resetUnitTestRootLogger() {
 
     // Prepare the objects to define the logging specification
     LoggerSpecification spec(getRootLoggerName(), 
-                             keaLoggerSeverity(isc::log::DEBUG),
+                             keaLoggerSeverity(verbose ? isc::log::DEBUG :
+                                               isc::log::INFO),
                              keaLoggerDbglevel(isc::log::MAX_DEBUG_LEVEL));
     OutputOption option;
 
@@ -145,7 +146,6 @@ resetUnitTestRootLogger() {
     manager.process(spec);
 }
 
-
 // Logger Run-Time Initialization via Environment Variables
 void initLogger(isc::log::Severity severity, int dbglevel) {
 
@@ -172,7 +172,7 @@ void initLogger(isc::log::Severity severity, int dbglevel) {
     // in the environment variables.  (The two-step approach is used as the
     // setUnitTestRootLoggerCharacteristics() function is used in several
     // places in the Kea tests, and it avoid duplicating code.)
-    resetUnitTestRootLogger();
+    isc::log::setDefaultLoggingOutput();
 } 
 
 } // namespace log
index 518460c9ab4bea4753067f3f0bc5257e456e597c..6a55d34544edfc4cecc511844cce165439ff14fd 100644 (file)
@@ -70,6 +70,10 @@ namespace log {
 /// be overridden by the tester.  It is not intended for use in production
 /// code.
 ///
+/// @note: Do NOT use this function in production code as it creates
+/// lockfile in the build dir. That's ok for tests, but not
+/// ok for production code.
+///
 /// @todo: Rename. This function overloads the initLogger() function that can
 ///       be used to initialize production programs.  This may lead to confusion.
 void initLogger(isc::log::Severity severity = isc::log::DEBUG,
@@ -107,17 +111,6 @@ isc::log::Severity keaLoggerSeverity(isc::log::Severity defseverity);
 /// \return Debug level to use.
 int keaLoggerDbglevel(int defdbglevel);
 
-
-/// \brief Reset root logger characteristics
-///
-/// This is a simplified interface into the resetting of the characteristics
-/// of the root logger.  It is aimed for use in unit tests and resets the
-/// characteristics of the root logger to use a severity, debug level and
-/// destination set by the environment variables KEA_LOGGER_SEVERITY,
-/// KEA_LOGGER_DBGLEVEL and KEA_LOGGER_DESTINATION.
-void
-resetUnitTestRootLogger();
-
 } // namespace log
 } // namespace isc
 
index 3f7f82055e907d4db00c7f7c959685e318e3f54c..c7cc305f5b44d23fffe580953b1980cd52bd25ff 100644 (file)
@@ -30,7 +30,7 @@ class LoggerLevelImplTest : public ::testing::Test {
 protected:
     LoggerLevelImplTest() {
         // Ensure logging set to default for unit tests
-        resetUnitTestRootLogger();
+        setDefaultLoggingOutput();
     }
 
     ~LoggerLevelImplTest()
index 641a6cccb76df5201608e6a939b436c0fccc6ffe..a52b283f2a9bcbd9a0f83573bade7766f5152a67 100644 (file)
@@ -31,7 +31,7 @@ protected:
     LoggerLevelTest() {
         // Logger initialization is done in main().  As logging tests may
         // alter the default logging output, it is reset here.
-        resetUnitTestRootLogger();
+        setDefaultLoggingOutput();
     }
     ~LoggerLevelTest() {
         LoggerManager::reset();
index c626c6dc50de735eb2e1404e8236d9ee975fecda..0eece4848539979f567129fff1b0ce7cc74afe22 100644 (file)
@@ -23,7 +23,7 @@ protected:
     LoggerSupportTest() {
         // Logger initialization is done in main().  As logging tests may
         // alter the default logging output, it is reset here.
-        resetUnitTestRootLogger();
+        setDefaultLoggingOutput();
     }
     ~LoggerSupportTest() {
     }