util: Add API to enumerate Logger modules

Change-Id: Ie1361b76305b4de9746e769212efa7b381c59f91
Refs: #4013
diff --git a/src/util/logging.cpp b/src/util/logging.cpp
index 89d0fd7..13fd36d 100644
--- a/src/util/logging.cpp
+++ b/src/util/logging.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2013-2016 Regents of the University of California.
+ * Copyright (c) 2013-2017 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -23,6 +23,8 @@
 #include "logger.hpp"
 
 #include <boost/log/expressions.hpp>
+#include <boost/range/algorithm/copy.hpp>
+#include <boost/range/adaptor/map.hpp>
 #include <cstdlib>
 #include <fstream>
 
@@ -66,6 +68,16 @@
   logger.setLevel(level);
 }
 
+std::set<std::string>
+Logging::getLoggerNamesImpl()
+{
+  std::lock_guard<std::mutex> lock(m_mutex);
+
+  std::set<std::string> loggerNames;
+  boost::copy(m_loggers | boost::adaptors::map_keys, std::inserter(loggerNames, loggerNames.end()));
+  return loggerNames;
+}
+
 #ifdef NDN_CXX_HAVE_TESTS
 bool
 Logging::removeLogger(Logger& logger)
diff --git a/src/util/logging.hpp b/src/util/logging.hpp
index 45dbe07..459cf2b 100644
--- a/src/util/logging.hpp
+++ b/src/util/logging.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2013-2016 Regents of the University of California.
+ * Copyright (c) 2013-2017 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -52,6 +52,11 @@
   static void
   addLogger(Logger& logger);
 
+  /** \brief get list of names of all registered loggers
+   */
+  static std::set<std::string>
+  getLoggerNames();
+
   /** \brief set severity level
    *  \param moduleName logger name, or "*" for default level
    *  \param level minimum severity level
@@ -111,6 +116,9 @@
   void
   addLoggerImpl(Logger& logger);
 
+  std::set<std::string>
+  getLoggerNamesImpl();
+
   void
   setLevelImpl(const std::string& moduleName, LogLevel level);
 
@@ -160,6 +168,12 @@
   get().addLoggerImpl(logger);
 }
 
+inline std::set<std::string>
+Logging::getLoggerNames()
+{
+  return get().getLoggerNamesImpl();
+}
+
 inline void
 Logging::setLevel(const std::string& moduleName, LogLevel level)
 {
diff --git a/tests/unit-tests/util/logging.t.cpp b/tests/unit-tests/util/logging.t.cpp
index f47b5a9..3447968 100644
--- a/tests/unit-tests/util/logging.t.cpp
+++ b/tests/unit-tests/util/logging.t.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2013-2016 Regents of the University of California.
+ * Copyright (c) 2013-2017 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -30,6 +30,8 @@
 namespace util {
 namespace tests {
 
+NDN_LOG_INIT(ndn.util.tests.Logging);
+
 using namespace ndn::tests;
 using boost::test_tools::output_test_stream;
 
@@ -90,6 +92,14 @@
 BOOST_AUTO_TEST_SUITE(Util)
 BOOST_FIXTURE_TEST_SUITE(TestLogging, LoggingFixture)
 
+BOOST_AUTO_TEST_CASE(GetLoggerNames)
+{
+  NDN_LOG_TRACE("GetLoggerNames"); // to avoid unused function warning
+  std::set<std::string> names = Logging::getLoggerNames();
+  BOOST_CHECK_GT(names.size(), 0);
+  BOOST_CHECK_EQUAL(names.count("ndn.util.tests.Logging"), 1);
+}
+
 BOOST_AUTO_TEST_SUITE(Severity)
 
 BOOST_AUTO_TEST_CASE(None)