core: reimplement logging using ndn-cxx's facility
Change-Id: Ifc7c5d70a61ad405dc1f1adfa522a2c0ad1586ab
Refs: #4580
diff --git a/core/log-config-section.cpp b/core/log-config-section.cpp
new file mode 100644
index 0000000..6f6f0ab
--- /dev/null
+++ b/core/log-config-section.cpp
@@ -0,0 +1,96 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2014-2018, Regents of the University of California,
+ * Arizona Board of Regents,
+ * Colorado State University,
+ * University Pierre & Marie Curie, Sorbonne University,
+ * Washington University in St. Louis,
+ * Beijing Institute of Technology,
+ * The University of Memphis.
+ *
+ * This file is part of NFD (Named Data Networking Forwarding Daemon).
+ * See AUTHORS.md for complete list of NFD authors and contributors.
+ *
+ * NFD is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "log-config-section.hpp"
+
+#include <ndn-cxx/util/logger.hpp>
+#include <ndn-cxx/util/logging.hpp>
+
+namespace nfd {
+namespace log {
+
+static ndn::util::LogLevel
+parseLogLevel(const ConfigSection& item, const std::string& key)
+{
+ try {
+ return ndn::util::parseLogLevel(item.get_value<std::string>());
+ }
+ catch (const std::invalid_argument& e) {
+ BOOST_THROW_EXCEPTION(ConfigFile::Error("Invalid setting for log." + key + ": " + e.what()));
+ }
+}
+
+static void
+onConfig(const ConfigSection& section, bool isDryRun, const std::string&)
+{
+ // log
+ // {
+ // ; default_level specifies the logging level for modules
+ // ; that are not explicitly named. All debugging levels
+ // ; listed above the selected value are enabled.
+ //
+ // default_level INFO
+ //
+ // ; You may also override the default for specific modules:
+ //
+ // FibManager DEBUG
+ // Forwarder WARN
+ // }
+
+ auto defaultLevel = ndn::util::LogLevel::INFO;
+ auto item = section.get_child_optional("default_level");
+ if (item) {
+ defaultLevel = parseLogLevel(*item, "default_level");
+ }
+ if (!isDryRun) {
+ // default_level applies only to NFD loggers
+ ndn::util::Logging::setLevel("nfd.*", defaultLevel);
+ }
+
+ for (const auto& i : section) {
+ if (i.first == "default_level") {
+ // do nothing
+ }
+ else {
+ auto level = parseLogLevel(i.second, i.first);
+ if (!isDryRun) {
+ if (i.first.find('.') == std::string::npos)
+ // backward compat: assume unqualified logger names refer to NFD loggers
+ ndn::util::Logging::setLevel("nfd." + i.first, level);
+ else
+ ndn::util::Logging::setLevel(i.first, level);
+ }
+ }
+ }
+}
+
+void
+setConfigFile(ConfigFile& config)
+{
+ config.addSectionHandler("log", &onConfig);
+}
+
+} // namespace log
+} // namespace nfd
diff --git a/core/log-config-section.hpp b/core/log-config-section.hpp
new file mode 100644
index 0000000..fbe35f9
--- /dev/null
+++ b/core/log-config-section.hpp
@@ -0,0 +1,40 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2014-2018, Regents of the University of California,
+ * Arizona Board of Regents,
+ * Colorado State University,
+ * University Pierre & Marie Curie, Sorbonne University,
+ * Washington University in St. Louis,
+ * Beijing Institute of Technology,
+ * The University of Memphis.
+ *
+ * This file is part of NFD (Named Data Networking Forwarding Daemon).
+ * See AUTHORS.md for complete list of NFD authors and contributors.
+ *
+ * NFD is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef NFD_CORE_LOG_CONFIG_SECTION_HPP
+#define NFD_CORE_LOG_CONFIG_SECTION_HPP
+
+#include "config-file.hpp"
+
+namespace nfd {
+namespace log {
+
+void
+setConfigFile(ConfigFile& config);
+
+} // namespace log
+} // namespace nfd
+
+#endif // NFD_CORE_LOG_CONFIG_SECTION_HPP
diff --git a/core/logger-factory.cpp b/core/logger-factory.cpp
deleted file mode 100644
index 215b087..0000000
--- a/core/logger-factory.cpp
+++ /dev/null
@@ -1,228 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2014-2017, Regents of the University of California,
- * Arizona Board of Regents,
- * Colorado State University,
- * University Pierre & Marie Curie, Sorbonne University,
- * Washington University in St. Louis,
- * Beijing Institute of Technology,
- * The University of Memphis.
- *
- * This file is part of NFD (Named Data Networking Forwarding Daemon).
- * See AUTHORS.md for complete list of NFD authors and contributors.
- *
- * NFD is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation,
- * either version 3 of the License, or (at your option) any later version.
- *
- * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "logger-factory.hpp"
-
-#include <ndn-cxx/util/logging.hpp>
-
-#include <boost/algorithm/string/case_conv.hpp>
-#include <boost/range/adaptor/map.hpp>
-
-#include <iostream>
-
-#ifdef HAVE_CUSTOM_LOGGER
-#error "This file should not be compiled when custom logger is used"
-#endif
-
-namespace nfd {
-
-NFD_LOG_INIT("LoggerFactory");
-
-LoggerFactory&
-LoggerFactory::getInstance()
-{
- static LoggerFactory globalLoggerFactory;
-
- return globalLoggerFactory;
-}
-
-LoggerFactory::LoggerFactory()
- : m_defaultLevel(LOG_INFO)
-{
- m_levelNames["NONE"] = LOG_NONE;
- m_levelNames["ERROR"] = LOG_ERROR;
- m_levelNames["WARN"] = LOG_WARN;
- m_levelNames["INFO"] = LOG_INFO;
- m_levelNames["DEBUG"] = LOG_DEBUG;
- m_levelNames["TRACE"] = LOG_TRACE;
- m_levelNames["ALL"] = LOG_ALL;
-
- // Let ndn-cxx logging facility initialize Boost.Log backend,
- // so that only one sink is attached to Boost.Log core.
- ndn::util::Logging::setDestination(std::clog);
-}
-
-LoggerFactory::~LoggerFactory()
-{
- ndn::util::Logging::flush();
-}
-
-void
-LoggerFactory::setConfigFile(ConfigFile& config)
-{
- config.addSectionHandler("log", bind(&LoggerFactory::onConfig, this, _1, _2, _3));
-}
-
-LogLevel
-LoggerFactory::parseLevel(const std::string& level)
-{
- std::string upperLevel = boost::to_upper_copy(level);
-
- // std::cerr << "parsing level: " << upperLevel << std::endl;;
- // std::cerr << "# levels: " << m_levelNames.size() << std::endl;
- // std::cerr << m_levelNames.begin()->first << std::endl;
-
- LevelMap::const_iterator levelIt = m_levelNames.find(upperLevel);
- if (levelIt != m_levelNames.end()) {
- return levelIt->second;
- }
- try {
- uint32_t levelNo = boost::lexical_cast<uint32_t>(level);
-
- if ((boost::lexical_cast<uint32_t>(LOG_NONE) <= levelNo &&
- levelNo <= boost::lexical_cast<uint32_t>(LOG_TRACE)) ||
- levelNo == LOG_ALL) {
- return static_cast<LogLevel>(levelNo);
- }
- }
- catch (const boost::bad_lexical_cast& error) {
- }
-
- BOOST_THROW_EXCEPTION(LoggerFactory::Error("Unsupported logging level \"" + level + "\""));
-}
-
-LogLevel
-LoggerFactory::extractLevel(const ConfigSection& item, const std::string& key)
-{
- std::string levelString;
- try {
- levelString = item.get_value<std::string>();
- }
- catch (const boost::property_tree::ptree_error& error) {
- }
-
- if (levelString.empty()) {
- BOOST_THROW_EXCEPTION(LoggerFactory::Error("No logging level found for option \"" + key + "\""));
- }
-
- return parseLevel(levelString);
-}
-
-void
-LoggerFactory::onConfig(const ConfigSection& section,
- bool isDryRun,
- const std::string& filename)
-{
- // log
- // {
- // ; default_level specifies the logging level for modules
- // ; that are not explicitly named. All debugging levels
- // ; listed above the selected value are enabled.
- //
- // default_level INFO
- //
- // ; You may also override the default for specific modules:
- //
- // FibManager DEBUG
- // Forwarder WARN
- // }
-
- if (!isDryRun) {
- ConfigSection::const_assoc_iterator item = section.find("default_level");
- if (item != section.not_found()) {
- LogLevel level = extractLevel(item->second, "default_level");
- setDefaultLevel(level);
- }
- else {
- setDefaultLevel(LOG_INFO);
- }
- }
-
- for (const auto& i : section) {
- LogLevel level = extractLevel(i.second, i.first);
-
- if (i.first == "default_level") {
- // do nothing
- }
- else {
- std::unique_lock<std::mutex> lock(m_loggersGuard);
- LoggerMap::iterator loggerIt = m_loggers.find(i.first);
- if (loggerIt == m_loggers.end()) {
- lock.unlock();
- NFD_LOG_DEBUG("Failed to configure logging level for module \"" <<
- i.first << "\" (module not found)");
- }
- else if (!isDryRun) {
- loggerIt->second.setLogLevel(level);
- lock.unlock();
- NFD_LOG_DEBUG("Changing level for module " << i.first << " to " << level);
- }
- }
- }
-}
-
-void
-LoggerFactory::setDefaultLevel(LogLevel level)
-{
- // std::cerr << "changing to default_level " << level << std::endl;
- std::lock_guard<std::mutex> lock(m_loggersGuard);
-
- m_defaultLevel = level;
- for (auto&& logger : m_loggers) {
- // std::cerr << "changing " << i->first << " to default " << m_defaultLevel << std::endl;
- logger.second.setLogLevel(m_defaultLevel);
- }
-}
-
-void
-LoggerFactory::flushBackend()
-{
- ndn::util::Logging::flush();
-}
-
-Logger&
-LoggerFactory::create(const std::string& moduleName)
-{
- return LoggerFactory::getInstance().createLogger(moduleName);
-}
-
-Logger&
-LoggerFactory::createLogger(const std::string& moduleName)
-{
- // std::cerr << "creating logger for " << moduleName
- // << " with level " << m_defaultLevel << std::endl;
-
- std::lock_guard<std::mutex> lock(m_loggersGuard);
-
- std::pair<LoggerMap::iterator, bool> loggerIt =
- m_loggers.insert(NameAndLogger(moduleName, Logger(moduleName, m_defaultLevel)));
-
- return loggerIt.first->second;
-}
-
-std::list<std::string>
-LoggerFactory::getModules() const
-{
- std::lock_guard<std::mutex> lock(m_loggersGuard);
-
- std::list<std::string> modules;
- for (const auto& loggerName : m_loggers | boost::adaptors::map_keys) {
- modules.push_back(loggerName);
- }
-
- return modules;
-}
-
-} // namespace nfd
diff --git a/core/logger-factory.hpp b/core/logger-factory.hpp
deleted file mode 100644
index 5cafc64..0000000
--- a/core/logger-factory.hpp
+++ /dev/null
@@ -1,126 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014-2016, Regents of the University of California,
- * Arizona Board of Regents,
- * Colorado State University,
- * University Pierre & Marie Curie, Sorbonne University,
- * Washington University in St. Louis,
- * Beijing Institute of Technology,
- * The University of Memphis.
- *
- * This file is part of NFD (Named Data Networking Forwarding Daemon).
- * See AUTHORS.md for complete list of NFD authors and contributors.
- *
- * NFD is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation,
- * either version 3 of the License, or (at your option) any later version.
- *
- * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef NFD_CORE_LOGGER_FACTORY_HPP
-#define NFD_CORE_LOGGER_FACTORY_HPP
-
-#include "common.hpp"
-
-#ifdef HAVE_CUSTOM_LOGGER
-#include "custom-logger-factory.hpp"
-#else
-
-#include "config-file.hpp"
-#include "logger.hpp"
-
-#include <mutex>
-
-namespace nfd {
-
-class LoggerFactory : noncopyable
-{
-public:
-
- class Error : public std::runtime_error
- {
- public:
- explicit
- Error(const std::string& error)
- : std::runtime_error(error)
- {
- }
- };
-
- static LoggerFactory&
- getInstance();
-
- void
- setConfigFile(ConfigFile& config);
-
- void
- onConfig(const ConfigSection& section, bool isDryRun, const std::string& filename);
-
- std::list<std::string>
- getModules() const;
-
- static Logger&
- create(const std::string& moduleName);
-
-
-PUBLIC_WITH_TESTS_ELSE_PRIVATE:
-
- // these methods are used during unit-testing
-
- LogLevel
- getDefaultLevel() const;
-
- void
- setDefaultLevel(LogLevel level);
-
- void
- flushBackend();
-
-private:
-
- LoggerFactory();
-
- ~LoggerFactory();
-
- Logger&
- createLogger(const std::string& moduleName);
-
- LogLevel
- parseLevel(const std::string& level);
-
- LogLevel
- extractLevel(const ConfigSection& item, const std::string& key);
-
-private:
-
- typedef std::map<std::string, LogLevel> LevelMap;
- typedef std::pair<std::string, LogLevel> NameAndLevel;
-
- LevelMap m_levelNames;
-
- typedef std::map<std::string, Logger> LoggerMap;
- typedef std::pair<std::string, Logger> NameAndLogger;
-
- LoggerMap m_loggers;
- mutable std::mutex m_loggersGuard;
-
- LogLevel m_defaultLevel;
-};
-
-inline LogLevel
-LoggerFactory::getDefaultLevel() const
-{
- return m_defaultLevel;
-}
-
-} // namespace nfd
-
-#endif // HAVE_CUSTOM_LOGGER
-
-#endif // NFD_CORE_LOGGER_FACTORY_HPP
diff --git a/core/logger.cpp b/core/logger.cpp
deleted file mode 100644
index d1f4e45..0000000
--- a/core/logger.cpp
+++ /dev/null
@@ -1,71 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2014-2018, Regents of the University of California,
- * Arizona Board of Regents,
- * Colorado State University,
- * University Pierre & Marie Curie, Sorbonne University,
- * Washington University in St. Louis,
- * Beijing Institute of Technology,
- * The University of Memphis.
- *
- * This file is part of NFD (Named Data Networking Forwarding Daemon).
- * See AUTHORS.md for complete list of NFD authors and contributors.
- *
- * NFD is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation,
- * either version 3 of the License, or (at your option) any later version.
- *
- * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "logger.hpp"
-
-#ifdef HAVE_CUSTOM_LOGGER
-#error "This file should not be compiled when custom logger is used"
-#endif
-
-#include <cinttypes>
-#include <cstdlib>
-#include <stdio.h>
-#include <type_traits>
-
-#include <ndn-cxx/util/time.hpp>
-
-namespace nfd {
-
-Logger::Logger(const std::string& name, LogLevel level)
- : m_moduleName(name)
- , m_enabledLogLevel(level)
-{
-}
-
-std::ostream&
-operator<<(std::ostream& os, const LoggerTimestamp&)
-{
- using namespace ndn::time;
-
- const auto sinceEpoch = system_clock::now().time_since_epoch();
- BOOST_ASSERT(sinceEpoch.count() >= 0);
- // use abs() to silence truncation warning in snprintf(), see #4365
- const auto usecs = std::abs(duration_cast<microseconds>(sinceEpoch).count());
- const auto usecsPerSec = microseconds::period::den;
-
- // 10 (whole seconds) + '.' + 6 (fraction) + '\0'
- char buffer[10 + 1 + 6 + 1];
- BOOST_ASSERT_MSG(usecs / usecsPerSec <= 9999999999, "whole seconds cannot fit in 10 characters");
-
- static_assert(std::is_same<microseconds::rep, int_least64_t>::value,
- "PRIdLEAST64 is incompatible with microseconds::rep");
- // std::snprintf unavailable on some platforms, see #2299
- ::snprintf(buffer, sizeof(buffer), "%" PRIdLEAST64 ".%06" PRIdLEAST64,
- usecs / usecsPerSec, usecs % usecsPerSec);
-
- return os << buffer;
-}
-
-} // namespace nfd
diff --git a/core/logger.hpp b/core/logger.hpp
index 24ec63c..b98ff61 100644
--- a/core/logger.hpp
+++ b/core/logger.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,146 +26,19 @@
#ifndef NFD_CORE_LOGGER_HPP
#define NFD_CORE_LOGGER_HPP
-#include "common.hpp"
+#include <ndn-cxx/util/logger.hpp>
-#ifdef HAVE_CUSTOM_LOGGER
-#include "custom-logger.hpp"
-#else
-#include <boost/log/common.hpp>
-#include <boost/log/sources/logger.hpp>
+#define NFD_LOG_INIT(name) NDN_LOG_INIT(nfd.name)
+#define NFD_LOG_MEMBER_DECL() NDN_LOG_MEMBER_DECL()
+#define NFD_LOG_MEMBER_DECL_SPECIALIZED(cls) NDN_LOG_MEMBER_DECL_SPECIALIZED(cls)
+#define NFD_LOG_MEMBER_INIT(cls, name) NDN_LOG_MEMBER_INIT(cls, nfd.name)
+#define NFD_LOG_MEMBER_INIT_SPECIALIZED(cls, name) NDN_LOG_MEMBER_INIT_SPECIALIZED(cls, nfd.name)
-namespace nfd {
-
-/** \brief indicates a log level
- * \note This type is internal. Logger should be accessed through NFD_LOG_* macros.
- */
-enum LogLevel {
- LOG_FATAL = -1, // fatal (will be logged unconditionally)
- LOG_NONE = 0, // no messages
- LOG_ERROR = 1, // serious error messages
- LOG_WARN = 2, // warning messages
- LOG_INFO = 3, // informational messages
- LOG_DEBUG = 4, // debug messages
- LOG_TRACE = 5, // trace messages (most verbose)
- LOG_ALL = 255 // all messages
-};
-
-/** \brief provides logging for a module
- * \note This type is internal. Logger should be accessed through NFD_LOG_* macros.
- * \note This type is copyable because logger can be declared as a field of
- * (usually template) classes, and shouldn't prevent those classes to be copyable.
- */
-class Logger
-{
-public:
- Logger(const std::string& name, LogLevel level);
-
- bool
- isEnabled(LogLevel level) const
- {
- return m_enabledLogLevel >= level;
- }
-
- void
- setLogLevel(LogLevel level)
- {
- m_enabledLogLevel = level;
- }
-
- const std::string&
- getName() const
- {
- return m_moduleName;
- }
-
- void
- setName(const std::string& name)
- {
- m_moduleName = name;
- }
-
-public:
- boost::log::sources::logger boostLogger;
-
-private:
- std::string m_moduleName;
- LogLevel m_enabledLogLevel;
-};
-
-inline std::ostream&
-operator<<(std::ostream& output, const Logger& logger)
-{
- output << logger.getName();
- return output;
-}
-
-/**
- * \brief a tag that writes a timestamp upon stream output
- */
-struct LoggerTimestamp
-{
-};
-
-/**
- * \brief write a timestamp to \p os
- * \note This function is thread-safe.
- */
-std::ostream&
-operator<<(std::ostream& os, const LoggerTimestamp&);
-
-} // namespace nfd
-
-#include "core/logger-factory.hpp"
-
-namespace nfd {
-
-#define NFD_LOG_INIT(name) \
-static ::nfd::Logger& g_logger = ::nfd::LoggerFactory::create(name)
-
-#define NFD_LOG_INCLASS_DECLARE() \
-static ::nfd::Logger& g_logger
-
-#define NFD_LOG_INCLASS_DEFINE(cls, name) \
-::nfd::Logger& cls::g_logger = ::nfd::LoggerFactory::create(name)
-
-#define NFD_LOG_INCLASS_TEMPLATE_DEFINE(cls, name) \
-template<class T> \
-::nfd::Logger& cls<T>::g_logger = ::nfd::LoggerFactory::create(name)
-
-#define NFD_LOG_INCLASS_TEMPLATE_SPECIALIZATION_DEFINE(cls, specialization, name) \
-template<> \
-::nfd::Logger& cls<specialization>::g_logger = ::nfd::LoggerFactory::create(name)
-
-#define NFD_LOG_INCLASS_2TEMPLATE_SPECIALIZATION_DEFINE(cls, s1, s2, name) \
-template<> \
-::nfd::Logger& cls<s1, s2>::g_logger = ::nfd::LoggerFactory::create(name)
-
-#if (BOOST_VERSION >= 105900) && (BOOST_VERSION < 106000)
-// workaround Boost bug 11549
-#define NFD_BOOST_LOG(x) BOOST_LOG(x) << ""
-#else
-#define NFD_BOOST_LOG(x) BOOST_LOG(x)
-#endif
-
-#define NFD_LOG_LINE(msg, expression) \
-::nfd::LoggerTimestamp{} << " "#msg": " << "[" << g_logger << "] " << expression
-
-#define NFD_LOG(level, msg, expression) \
- do { \
- if (g_logger.isEnabled(::nfd::LOG_##level)) { \
- NFD_BOOST_LOG(g_logger.boostLogger) << NFD_LOG_LINE(msg, expression); \
- } \
- } while (false)
-
-#define NFD_LOG_TRACE(expression) NFD_LOG(TRACE, TRACE, expression)
-#define NFD_LOG_DEBUG(expression) NFD_LOG(DEBUG, DEBUG, expression)
-#define NFD_LOG_INFO(expression) NFD_LOG(INFO, INFO, expression)
-#define NFD_LOG_WARN(expression) NFD_LOG(WARN, WARNING, expression)
-#define NFD_LOG_ERROR(expression) NFD_LOG(ERROR, ERROR, expression)
-#define NFD_LOG_FATAL(expression) NFD_LOG(FATAL, FATAL, expression)
-
-} // namespace nfd
-
-#endif // HAVE_CUSTOM_LOGGER
+#define NFD_LOG_TRACE NDN_LOG_TRACE
+#define NFD_LOG_DEBUG NDN_LOG_DEBUG
+#define NFD_LOG_INFO NDN_LOG_INFO
+#define NFD_LOG_WARN NDN_LOG_WARN
+#define NFD_LOG_ERROR NDN_LOG_ERROR
+#define NFD_LOG_FATAL NDN_LOG_FATAL
#endif // NFD_CORE_LOGGER_HPP
diff --git a/core/privilege-helper.cpp b/core/privilege-helper.cpp
index edc8336..923efa4 100644
--- a/core/privilege-helper.cpp
+++ b/core/privilege-helper.cpp
@@ -31,7 +31,7 @@
namespace nfd {
-NFD_LOG_INIT("PrivilegeHelper");
+NFD_LOG_INIT(PrivilegeHelper);
#ifdef HAVE_PRIVILEGE_DROP_AND_ELEVATE
uid_t PrivilegeHelper::s_normalUid = ::geteuid();
@@ -123,6 +123,9 @@
void
PrivilegeHelper::drop()
{
+ if (::geteuid() == s_normalUid && ::getegid() == s_normalGid)
+ return;
+
#ifdef HAVE_PRIVILEGE_DROP_AND_ELEVATE
NFD_LOG_TRACE("dropping to effective gid=" << s_normalGid);
if (::setegid(s_normalGid) != 0)
@@ -141,6 +144,9 @@
void
PrivilegeHelper::raise()
{
+ if (::geteuid() == s_privilegedUid && ::getegid() == s_privilegedGid)
+ return;
+
#ifdef HAVE_PRIVILEGE_DROP_AND_ELEVATE
NFD_LOG_TRACE("elevating to effective uid=" << s_privilegedUid);
if (::seteuid(s_privilegedUid) != 0)