core: reimplement logging using ndn-cxx's facility
Change-Id: Ifc7c5d70a61ad405dc1f1adfa522a2c0ad1586ab
Refs: #4580
diff --git a/rib/auto-prefix-propagator.cpp b/rib/auto-prefix-propagator.cpp
index d3e9e86..13124d2 100644
--- a/rib/auto-prefix-propagator.cpp
+++ b/rib/auto-prefix-propagator.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014-2017, Regents of the University of California,
+/*
+ * Copyright (c) 2014-2018, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -26,16 +26,16 @@
#include "auto-prefix-propagator.hpp"
#include "core/logger.hpp"
#include "core/scheduler.hpp"
+
#include <ndn-cxx/security/pib/identity.hpp>
#include <ndn-cxx/security/pib/identity-container.hpp>
#include <ndn-cxx/security/pib/pib.hpp>
#include <ndn-cxx/security/signing-helpers.hpp>
-#include <vector>
namespace nfd {
namespace rib {
-NFD_LOG_INIT("AutoPrefixPropagator");
+NFD_LOG_INIT(AutoPrefixPropagator);
using ndn::nfd::ControlParameters;
using ndn::nfd::CommandOptions;
diff --git a/rib/fib-updater.cpp b/rib/fib-updater.cpp
index bce3a5d..76a33c7 100644
--- a/rib/fib-updater.cpp
+++ b/rib/fib-updater.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014-2017, Regents of the University of California,
+/*
+ * Copyright (c) 2014-2018, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -24,7 +24,6 @@
*/
#include "fib-updater.hpp"
-
#include "core/logger.hpp"
#include <ndn-cxx/mgmt/nfd/control-parameters.hpp>
@@ -32,9 +31,9 @@
namespace nfd {
namespace rib {
-using ndn::nfd::ControlParameters;
+NFD_LOG_INIT(FibUpdater);
-NFD_LOG_INIT("FibUpdater");
+using ndn::nfd::ControlParameters;
const unsigned int FibUpdater::MAX_NUM_TIMEOUTS = 10;
const uint32_t FibUpdater::ERROR_FACE_NOT_FOUND = 410;
diff --git a/rib/propagated-entry.cpp b/rib/propagated-entry.cpp
index 8dff54a..dae3934 100644
--- a/rib/propagated-entry.cpp
+++ b/rib/propagated-entry.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014-2015, Regents of the University of California,
+/*
+ * Copyright (c) 2014-2018, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -23,7 +23,6 @@
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "core/logger.hpp"
#include "propagated-entry.hpp"
namespace nfd {
diff --git a/rib/readvertise/nfd-rib-readvertise-destination.cpp b/rib/readvertise/nfd-rib-readvertise-destination.cpp
index 3d19004..530a9d4 100644
--- a/rib/readvertise/nfd-rib-readvertise-destination.cpp
+++ b/rib/readvertise/nfd-rib-readvertise-destination.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014-2017, Regents of the University of California,
+/*
+ * Copyright (c) 2014-2018, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -34,7 +34,7 @@
namespace nfd {
namespace rib {
-NFD_LOG_INIT("NfdRibReadvertiseDestination");
+NFD_LOG_INIT(NfdRibReadvertiseDestination);
using ndn::nfd::CommandOptions;
using ndn::nfd::ControlParameters;
diff --git a/rib/readvertise/readvertise-destination.cpp b/rib/readvertise/readvertise-destination.cpp
index 3c577c7..a687a8a 100644
--- a/rib/readvertise/readvertise-destination.cpp
+++ b/rib/readvertise/readvertise-destination.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014-2017, Regents of the University of California,
+/*
+ * Copyright (c) 2014-2018, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -29,7 +29,7 @@
namespace nfd {
namespace rib {
-NFD_LOG_INIT("ReadvertiseDestination");
+NFD_LOG_INIT(ReadvertiseDestination);
void
ReadvertiseDestination::setAvailability(bool isAvailable)
diff --git a/rib/readvertise/readvertise.cpp b/rib/readvertise/readvertise.cpp
index 344bc7e..53074f8 100644
--- a/rib/readvertise/readvertise.cpp
+++ b/rib/readvertise/readvertise.cpp
@@ -30,7 +30,7 @@
namespace nfd {
namespace rib {
-NFD_LOG_INIT("Readvertise");
+NFD_LOG_INIT(Readvertise);
const time::milliseconds Readvertise::RETRY_DELAY_MIN = time::seconds(50);
const time::milliseconds Readvertise::RETRY_DELAY_MAX = time::seconds(3600);
diff --git a/rib/rib-entry.cpp b/rib/rib-entry.cpp
index e26e6d6..7fd0ed7 100644
--- a/rib/rib-entry.cpp
+++ b/rib/rib-entry.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014-2017, Regents of the University of California,
+/*
+ * Copyright (c) 2014-2018, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -24,16 +24,15 @@
*/
#include "rib-entry.hpp"
-
#include "core/logger.hpp"
#include <ndn-cxx/mgmt/nfd/control-command.hpp>
-NFD_LOG_INIT("RibEntry");
-
namespace nfd {
namespace rib {
+NFD_LOG_INIT(RibEntry);
+
RibEntry::RouteList::iterator
RibEntry::findRoute(const Route& route)
{
diff --git a/rib/rib-manager.cpp b/rib/rib-manager.cpp
index c955a0d..ecf20d9 100644
--- a/rib/rib-manager.cpp
+++ b/rib/rib-manager.cpp
@@ -42,7 +42,7 @@
namespace nfd {
namespace rib {
-NFD_LOG_INIT("RibManager");
+NFD_LOG_INIT(RibManager);
const Name RibManager::LOCAL_HOST_TOP_PREFIX = "/localhost/nfd";
const Name RibManager::LOCAL_HOP_TOP_PREFIX = "/localhop/nfd";
diff --git a/rib/rib.cpp b/rib/rib.cpp
index a2a27fb..d6b125b 100644
--- a/rib/rib.cpp
+++ b/rib/rib.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014-2017, Regents of the University of California,
+/*
+ * Copyright (c) 2014-2018, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -24,15 +24,14 @@
*/
#include "rib.hpp"
-
#include "fib-updater.hpp"
#include "core/logger.hpp"
-NFD_LOG_INIT("Rib");
-
namespace nfd {
namespace rib {
+NFD_LOG_INIT(Rib);
+
bool
operator<(const RibRouteRef& lhs, const RibRouteRef& rhs)
{
@@ -52,9 +51,7 @@
{
}
-Rib::~Rib()
-{
-}
+Rib::~Rib() = default;
void
Rib::setFibUpdater(FibUpdater* updater)
diff --git a/rib/service.cpp b/rib/service.cpp
index 51ba11c..dce806f 100644
--- a/rib/service.cpp
+++ b/rib/service.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014-2016, Regents of the University of California,
+/*
+ * Copyright (c) 2014-2018, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -24,10 +24,7 @@
*/
#include "service.hpp"
-
#include "rib-manager.hpp"
-#include "core/config-file.hpp"
-#include "core/logger-factory.hpp"
#include "core/global-io.hpp"
#include <boost/property_tree/info_parser.hpp>
@@ -52,32 +49,23 @@
{
}
-Service::~Service()
-{
- // It is necessary to explicitly define the destructor, because some member variables
- // (e.g., unique_ptr<RibManager>) are forward-declared, but implicitly declared destructor
- // requires complete types for all members when instantiated.
-}
+// It is necessary to explicitly define the destructor, because some member variables
+// (e.g., unique_ptr<RibManager>) are forward-declared, but implicitly declared destructor
+// requires complete types for all members when instantiated.
+Service::~Service() = default;
void
Service::initialize()
{
- m_face.reset(new ndn::Face(getLocalNfdTransport(), getGlobalIoService(), m_keyChain));
- m_dispatcher.reset(new ndn::mgmt::Dispatcher(*m_face, m_keyChain));
-
- initializeLogging();
-
- m_ribManager.reset(new RibManager(*m_dispatcher, *m_face, m_keyChain));
+ m_face = make_unique<ndn::Face>(getLocalNfdTransport(), getGlobalIoService(), m_keyChain);
+ m_dispatcher = make_unique<ndn::mgmt::Dispatcher>(*m_face, m_keyChain);
+ m_ribManager = make_unique<RibManager>(*m_dispatcher, *m_face, m_keyChain);
ConfigFile config([] (const std::string& filename, const std::string& sectionName,
const ConfigSection& section, bool isDryRun) {
- // Ignore "log" and sections belonging to NFD,
- // but raise an error if we're missing a handler for a "rib" section.
- if (sectionName != "rib" || sectionName == "log") {
- // do nothing
- }
- else {
- // missing "rib" section handler
+ // Ignore sections belonging to NFD, but raise an error
+ // if we're missing a handler for a "rib" section.
+ if (sectionName == "rib") {
ConfigFile::throwErrorOnUnknownSection(filename, sectionName, section, isDryRun);
}
});
@@ -97,22 +85,6 @@
m_ribManager->enableLocalFields();
}
-void
-Service::initializeLogging()
-{
- ConfigFile config(&ConfigFile::ignoreUnknownSection);
- LoggerFactory::getInstance().setConfigFile(config);
-
- if (!m_configFile.empty()) {
- config.parse(m_configFile, true);
- config.parse(m_configFile, false);
- }
- else {
- config.parse(m_configSection, true, INTERNAL_CONFIG);
- config.parse(m_configSection, false, INTERNAL_CONFIG);
- }
-}
-
shared_ptr<ndn::Transport>
Service::getLocalNfdTransport()
{
@@ -123,13 +95,14 @@
// If error is thrown at this point, it is development error
boost::property_tree::read_info(m_configFile, config);
}
- else
+ else {
config = m_configSection;
+ }
if (config.get_child_optional("face_system.unix")) {
// unix socket enabled
- auto&& socketPath = config.get<std::string>("face_system.unix.path", "/var/run/nfd.sock");
+ auto socketPath = config.get<std::string>("face_system.unix.path", "/var/run/nfd.sock");
// default socketPath should be the same as in FaceManager::processSectionUnix
return make_shared<ndn::UnixTransport>(socketPath);
@@ -138,7 +111,7 @@
config.get<std::string>("face_system.tcp.listen", "yes") == "yes") {
// tcp is enabled
- auto&& port = config.get<std::string>("face_system.tcp.port", "6363");
+ auto port = config.get<std::string>("face_system.tcp.port", "6363");
// default port should be the same as in FaceManager::processSectionTcp
return make_shared<ndn::TcpTransport>("localhost", port);
diff --git a/rib/service.hpp b/rib/service.hpp
index ae7b23f..35223dc 100644
--- a/rib/service.hpp
+++ b/rib/service.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014-2016, Regents of the University of California,
+/*
+ * Copyright (c) 2014-2018, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -26,13 +26,12 @@
#ifndef NFD_RIB_SERVICE_HPP
#define NFD_RIB_SERVICE_HPP
-#include "core/common.hpp"
#include "core/config-file.hpp"
#include <ndn-cxx/face.hpp>
+#include <ndn-cxx/mgmt/dispatcher.hpp>
#include <ndn-cxx/security/key-chain.hpp>
#include <ndn-cxx/transport/transport.hpp>
-#include <ndn-cxx/mgmt/dispatcher.hpp>
namespace nfd {
namespace rib {
@@ -86,9 +85,6 @@
initialize();
private:
- void
- initializeLogging();
-
/**
* \brief Look into the config file and construct appropriate transport to communicate with NFD
* If NFD-RIB instance was initialized with config file, INFO format is assumed