core: Specify fully-qualified namespaces in logging macros

Without the full specification, compilation may fail if the logging
used outside ::nfd namespace, e.g., in NFD tools.

Change-Id: I24d733acf920bc90521ac457ae1fe6c846a1fe3e
diff --git a/core/logger.hpp b/core/logger.hpp
index 853a922..e7fa884 100644
--- a/core/logger.hpp
+++ b/core/logger.hpp
@@ -120,28 +120,28 @@
 namespace nfd {
 
 #define NFD_LOG_INIT(name) \
-static nfd::Logger& g_logger = nfd::LoggerFactory::create(name)
+static ::nfd::Logger& g_logger = ::nfd::LoggerFactory::create(name)
 
 #define NFD_LOG_INCLASS_DECLARE() \
-static nfd::Logger& g_logger
+static ::nfd::Logger& g_logger
 
 #define NFD_LOG_INCLASS_DEFINE(cls, name) \
-nfd::Logger& cls::g_logger = nfd::LoggerFactory::create(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)
+::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)
+::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)
+::nfd::Logger& cls<s1, s2>::g_logger = ::nfd::LoggerFactory::create(name)
 
 #define NFD_LOG_LINE(msg, expression) \
-LoggerTimestamp{} << " "#msg": " << "[" << g_logger  << "] " << expression
+::nfd::LoggerTimestamp{} << " "#msg": " << "[" << g_logger  << "] " << expression
 
 #define NFD_LOG(level, msg, expression)                                 \
   do {                                                                  \
diff --git a/tests/core/logger.t.cpp b/tests/core/logger.t.cpp
index 51dd2d2..07373e5 100644
--- a/tests/core/logger.t.cpp
+++ b/tests/core/logger.t.cpp
@@ -903,3 +903,88 @@
 
 } // namespace tests
 } // namespace nfd
+
+// Testing compilation of the logger outside ::nfd namespace
+
+namespace test_logger { // another root namespace
+
+void
+Test1()
+{
+  NFD_LOG_INIT("Test");
+
+  NFD_LOG_TRACE("Trace");
+  NFD_LOG_DEBUG("Debug");
+  NFD_LOG_INFO("Info");
+  NFD_LOG_WARN("Warn");
+  NFD_LOG_ERROR("Error");
+  NFD_LOG_FATAL("Fatal");
+}
+
+class Test2
+{
+  NFD_LOG_INCLASS_DECLARE();
+};
+
+NFD_LOG_INCLASS_DEFINE(Test2, "Test2");
+
+template<class T>
+class Test3
+{
+  NFD_LOG_INCLASS_DECLARE();
+};
+
+NFD_LOG_INCLASS_TEMPLATE_DEFINE(Test3, "Test3");
+
+NFD_LOG_INCLASS_TEMPLATE_SPECIALIZATION_DEFINE(Test3, int, "Test3Int");
+
+template<class X, class Y>
+class Test4
+{
+  NFD_LOG_INCLASS_DECLARE();
+};
+
+NFD_LOG_INCLASS_2TEMPLATE_SPECIALIZATION_DEFINE(Test4, int, int, "Test4IntInt");
+
+namespace nfd { // nested nfd namespace, different from ::nfd
+
+void
+Test1()
+{
+  NFD_LOG_INIT("Test");
+
+  NFD_LOG_TRACE("Trace");
+  NFD_LOG_DEBUG("Debug");
+  NFD_LOG_INFO("Info");
+  NFD_LOG_WARN("Warn");
+  NFD_LOG_ERROR("Error");
+  NFD_LOG_FATAL("Fatal");
+}
+
+class Test2
+{
+  NFD_LOG_INCLASS_DECLARE();
+};
+
+NFD_LOG_INCLASS_DEFINE(Test2, "Test2");
+
+template<class T>
+class Test3
+{
+  NFD_LOG_INCLASS_DECLARE();
+};
+
+NFD_LOG_INCLASS_TEMPLATE_DEFINE(Test3, "Test3");
+
+NFD_LOG_INCLASS_TEMPLATE_SPECIALIZATION_DEFINE(Test3, int, "Test3Int");
+
+template<class X, class Y>
+class Test4
+{
+  NFD_LOG_INCLASS_DECLARE();
+};
+
+NFD_LOG_INCLASS_2TEMPLATE_SPECIALIZATION_DEFINE(Test4, int, int, "Test4IntInt");
+
+} // namespace nfd
+} // namespace test_logger