Parcourir la source

[3591] Default logging refactored.

Tomek Mrugalski il y a 10 ans
Parent
commit
e2a3d672e2

+ 4 - 0
Makefile.am

@@ -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

+ 1 - 1
src/bin/d2/tests/Makefile.am

@@ -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
 

+ 1 - 1
src/bin/dhcp4/tests/Makefile.am

@@ -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
 

+ 1 - 1
src/bin/dhcp6/tests/Makefile.am

@@ -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
 

+ 1 - 0
src/bin/keactrl/tests/Makefile.am

@@ -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 ; \

+ 2 - 5
src/lib/dhcpsrv/daemon.cc

@@ -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)

+ 4 - 9
src/lib/dhcpsrv/logging.cc

@@ -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

+ 1 - 1
src/lib/log/interprocess/Makefile.am

@@ -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)

+ 11 - 0
src/lib/log/logger_support.h

@@ -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
 

+ 4 - 4
src/lib/log/logger_unittest_support.cc

@@ -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

+ 4 - 11
src/lib/log/logger_unittest_support.h

@@ -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
 

+ 1 - 1
src/lib/log/tests/logger_level_impl_unittest.cc

@@ -30,7 +30,7 @@ class LoggerLevelImplTest : public ::testing::Test {
 protected:
     LoggerLevelImplTest() {
         // Ensure logging set to default for unit tests
-        resetUnitTestRootLogger();
+        setDefaultLoggingOutput();
     }
 
     ~LoggerLevelImplTest()

+ 1 - 1
src/lib/log/tests/logger_level_unittest.cc

@@ -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();

+ 1 - 1
src/lib/log/tests/logger_support_unittest.cc

@@ -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() {
     }