From: Shawn Routhier Date: Sat, 14 Feb 2015 01:43:28 +0000 (-0800) Subject: [trac3667] Updates per review X-Git-Tag: trac3712_base~5^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=59e1089ffafdacc665a3c4ba92beb11bddb19028;p=thirdparty%2Fkea.git [trac3667] Updates per review Move lease_stats.h to leae_file_stats.h Move logging init code into its own function. --- diff --git a/ChangeLog b/ChangeLog index b9491567bb..9fdce0fad9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +XXX. [func] sar + A class, LeaseFileStats, has been added to provide simple + statistics for use with lease files. Also added logging + to the kea-lfc process per the design. + See http://kea.isc.org/wiki/LFCDesign for the design. + (Trac #3667, git ) + 887. [func] sar A new process, kea-lfc, has been added. It is meant to be periodically executed by the DHCPv4 and DHCPv6 servers diff --git a/src/bin/lfc/lfc_controller.cc b/src/bin/lfc/lfc_controller.cc index f4430e3bd9..4cf18065fe 100644 --- a/src/bin/lfc/lfc_controller.cc +++ b/src/bin/lfc/lfc_controller.cc @@ -77,37 +77,9 @@ LFCController::launch(int argc, char* argv[], const bool test_mode) { usage(ex.what()); throw; // rethrow it } - // If we are running in test mode use the environment variables - // else use our defaults - if (test_mode) { - initLogger(); - } - else { - OutputOption option; - LoggerManager manager; - - initLogger(lfc_app_name_, INFO, 0, NULL, false); - - // Prepare the objects to define the logging specification - LoggerSpecification spec(getRootLoggerName(), - keaLoggerSeverity(INFO), - keaLoggerDbglevel(0)); - - // If we are running in verbose (debugging) mode - // we send the output to the console, otherwise - // by default we send it to the SYSLOG - if (verbose_) { - option.destination = OutputOption::DEST_CONSOLE; - } else { - option.destination = OutputOption::DEST_SYSLOG; - - } - - // ... and set the destination - spec.addOutputOption(option); - manager.process(spec); - } + // Start up the logging system. + startLogger(test_mode); LOG_INFO(lfc_logger, LFC_START); @@ -419,5 +391,40 @@ LFCController::fileRotate() const { << ") error: " << strerror(errno)); } } + +void +LFCController::startLogger(const bool test_mode) const { + // If we are running in test mode use the environment variables + // else use our defaults + if (test_mode) { + initLogger(); + } + else { + OutputOption option; + LoggerManager manager; + + initLogger(lfc_app_name_, INFO, 0, NULL, false); + + // Prepare the objects to define the logging specification + LoggerSpecification spec(getRootLoggerName(), + keaLoggerSeverity(INFO), + keaLoggerDbglevel(0)); + + // If we are running in verbose (debugging) mode + // we send the output to the console, otherwise + // by default we send it to the SYSLOG + if (verbose_) { + option.destination = OutputOption::DEST_CONSOLE; + } else { + option.destination = OutputOption::DEST_SYSLOG; + } + + // ... and set the destination + spec.addOutputOption(option); + + manager.process(spec); + } +} + }; // namespace isc::lfc }; // namespace isc diff --git a/src/bin/lfc/lfc_controller.h b/src/bin/lfc/lfc_controller.h index 73aa6e76f8..934527aa73 100644 --- a/src/bin/lfc/lfc_controller.h +++ b/src/bin/lfc/lfc_controller.h @@ -196,6 +196,12 @@ private: /// @throw RunTimeFail if we can't move the file. template void processLeases() const; + + ///@brief Start up the logging system + /// + /// @param test_mode indicates if we have have been started from the test + /// system (true) or are running normally (false) + void startLogger(const bool test_mode) const; }; }; // namespace isc::lfc diff --git a/src/bin/lfc/tests/lfc_controller_unittests.cc b/src/bin/lfc/tests/lfc_controller_unittests.cc index a697eb5d61..cd7e12ce55 100644 --- a/src/bin/lfc/tests/lfc_controller_unittests.cc +++ b/src/bin/lfc/tests/lfc_controller_unittests.cc @@ -109,7 +109,7 @@ protected: /// lfcController::launch for details. This is wrapped to provide /// a single place to update the test_mode throughout the file. void launch(LFCController lfc_controller, int argc, char* argv[]) { - lfc_controller.launch(argc, argv, false); + lfc_controller.launch(argc, argv, true); } private: diff --git a/src/lib/dhcpsrv/Makefile.am b/src/lib/dhcpsrv/Makefile.am index d1b1178655..6b22a8f7b1 100644 --- a/src/lib/dhcpsrv/Makefile.am +++ b/src/lib/dhcpsrv/Makefile.am @@ -83,9 +83,9 @@ libkea_dhcpsrv_la_SOURCES += host_mgr.cc host_mgr.h libkea_dhcpsrv_la_SOURCES += key_from_key.h libkea_dhcpsrv_la_SOURCES += lease.cc lease.h libkea_dhcpsrv_la_SOURCES += lease_file_loader.h +libkea_dhcpsrv_la_SOURCES += lease_file_stats.h libkea_dhcpsrv_la_SOURCES += lease_mgr.cc lease_mgr.h libkea_dhcpsrv_la_SOURCES += lease_mgr_factory.cc lease_mgr_factory.h -libkea_dhcpsrv_la_SOURCES += lease_stats.h libkea_dhcpsrv_la_SOURCES += logging.cc logging.h libkea_dhcpsrv_la_SOURCES += logging_info.cc logging_info.h libkea_dhcpsrv_la_SOURCES += memfile_lease_mgr.cc memfile_lease_mgr.h diff --git a/src/lib/dhcpsrv/csv_lease_file4.h b/src/lib/dhcpsrv/csv_lease_file4.h index 21041defe6..dc34760e63 100644 --- a/src/lib/dhcpsrv/csv_lease_file4.h +++ b/src/lib/dhcpsrv/csv_lease_file4.h @@ -19,7 +19,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/lib/dhcpsrv/csv_lease_file6.h b/src/lib/dhcpsrv/csv_lease_file6.h index 9e11e1179a..64b402d9af 100644 --- a/src/lib/dhcpsrv/csv_lease_file6.h +++ b/src/lib/dhcpsrv/csv_lease_file6.h @@ -19,7 +19,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/lib/dhcpsrv/lease_stats.h b/src/lib/dhcpsrv/lease_file_stats.h similarity index 97% rename from src/lib/dhcpsrv/lease_stats.h rename to src/lib/dhcpsrv/lease_file_stats.h index 3c5f5f09f3..6c6b15752b 100644 --- a/src/lib/dhcpsrv/lease_stats.h +++ b/src/lib/dhcpsrv/lease_file_stats.h @@ -12,8 +12,8 @@ // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR // PERFORMANCE OF THIS SOFTWARE. -#ifndef LEASE_STATS_H -#define LEASE_STATS_H +#ifndef LEASE_FILE_STATS_H +#define LEASE_FILE_STATS_H namespace isc { namespace dhcp { @@ -99,4 +99,4 @@ protected: } // namespace isc::dhcp } // namesapce isc -#endif // LEASE_STATS_H +#endif // LEASE_FILE_STATS_H