From: Tomek Mrugalski Date: Fri, 12 Sep 2014 15:20:47 +0000 (+0200) Subject: [3591] Default logging refactored. X-Git-Tag: rt3470_base~12^2~9 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e2a3d672e20450cd35694f7a94ee19d7f286477e;p=thirdparty%2Fkea.git [3591] Default logging refactored. --- diff --git a/Makefile.am b/Makefile.am index 25dd138bef..887e3b5860 100644 --- a/Makefile.am +++ b/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 diff --git a/src/bin/d2/tests/Makefile.am b/src/bin/d2/tests/Makefile.am index 98f987cbba..e518fe9fb9 100644 --- a/src/bin/d2/tests/Makefile.am +++ b/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 diff --git a/src/bin/dhcp4/tests/Makefile.am b/src/bin/dhcp4/tests/Makefile.am index 727753b806..2c7bf627c8 100644 --- a/src/bin/dhcp4/tests/Makefile.am +++ b/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 diff --git a/src/bin/dhcp6/tests/Makefile.am b/src/bin/dhcp6/tests/Makefile.am index b54b9e9948..c530f3c9ff 100644 --- a/src/bin/dhcp6/tests/Makefile.am +++ b/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 diff --git a/src/bin/keactrl/tests/Makefile.am b/src/bin/keactrl/tests/Makefile.am index 7ff0952cf9..b692cbe41a 100644 --- a/src/bin/keactrl/tests/Makefile.am +++ b/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 ; \ diff --git a/src/lib/dhcpsrv/daemon.cc b/src/lib/dhcpsrv/daemon.cc index fdf4bce1bd..6922b276c9 100644 --- a/src/lib/dhcpsrv/daemon.cc +++ b/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) diff --git a/src/lib/dhcpsrv/logging.cc b/src/lib/dhcpsrv/logging.cc index 27ec41dfc3..0a5a8b5f54 100644 --- a/src/lib/dhcpsrv/logging.cc +++ b/src/lib/dhcpsrv/logging.cc @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -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 diff --git a/src/lib/log/interprocess/Makefile.am b/src/lib/log/interprocess/Makefile.am index 4becc0d9a1..2e949d16b8 100644 --- a/src/lib/log/interprocess/Makefile.am +++ b/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) diff --git a/src/lib/log/logger_support.h b/src/lib/log/logger_support.h index bd3b5b3d62..6caa61beb2 100644 --- a/src/lib/log/logger_support.h +++ b/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 diff --git a/src/lib/log/logger_unittest_support.cc b/src/lib/log/logger_unittest_support.cc index 539f05118d..9c4d601f5a 100644 --- a/src/lib/log/logger_unittest_support.cc +++ b/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 diff --git a/src/lib/log/logger_unittest_support.h b/src/lib/log/logger_unittest_support.h index 518460c9ab..6a55d34544 100644 --- a/src/lib/log/logger_unittest_support.h +++ b/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 diff --git a/src/lib/log/tests/logger_level_impl_unittest.cc b/src/lib/log/tests/logger_level_impl_unittest.cc index 3f7f82055e..c7cc305f5b 100644 --- a/src/lib/log/tests/logger_level_impl_unittest.cc +++ b/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() diff --git a/src/lib/log/tests/logger_level_unittest.cc b/src/lib/log/tests/logger_level_unittest.cc index 641a6cccb7..a52b283f2a 100644 --- a/src/lib/log/tests/logger_level_unittest.cc +++ b/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(); diff --git a/src/lib/log/tests/logger_support_unittest.cc b/src/lib/log/tests/logger_support_unittest.cc index c626c6dc50..0eece48485 100644 --- a/src/lib/log/tests/logger_support_unittest.cc +++ b/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() { }