core: Allow customization of Logger and LoggerFactory

Change-Id: I48a8217ab4cfb34ce2993f11a26266723d8d2923
Refs: #2433
diff --git a/core/logger-factory.cpp b/core/logger-factory.cpp
index b0ef3cd..483387f 100644
--- a/core/logger-factory.cpp
+++ b/core/logger-factory.cpp
@@ -1,11 +1,12 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014  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
+ * Copyright (c) 2014-2015,  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.
@@ -20,10 +21,14 @@
  *
  * 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"
 
+#ifdef HAVE_CUSTOM_LOGGER
+#error "This file should not be compiled when custom logger is used"
+#endif
+
 namespace nfd {
 
 NFD_LOG_INIT("LoggerFactory");
diff --git a/core/logger-factory.hpp b/core/logger-factory.hpp
index cbf7424..9f4a9f3 100644
--- a/core/logger-factory.hpp
+++ b/core/logger-factory.hpp
@@ -1,11 +1,12 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014  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
+ * Copyright (c) 2014-2015,  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.
@@ -20,12 +21,17 @@
  *
  * 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"
 
@@ -107,4 +113,6 @@
 
 } // namespace nfd
 
+#endif // HAVE_CUSTOM_LOGGER
+
 #endif // NFD_CORE_LOGGER_FACTORY_HPP
diff --git a/core/logger.cpp b/core/logger.cpp
index e971613..5ba8c39 100644
--- a/core/logger.cpp
+++ b/core/logger.cpp
@@ -24,6 +24,11 @@
  */
 
 #include "logger.hpp"
+
+#ifdef HAVE_CUSTOM_LOGGER
+#error "This file should not be compiled when custom logger is used"
+#endif
+
 #include <ndn-cxx/util/time.hpp>
 #include <cinttypes>
 #include <stdio.h>
diff --git a/core/logger.hpp b/core/logger.hpp
index 5efee3c..6d01fa0 100644
--- a/core/logger.hpp
+++ b/core/logger.hpp
@@ -1,12 +1,12 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014,  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
+ * Copyright (c) 2014-2015,  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.
@@ -28,19 +28,23 @@
 
 #include "common.hpp"
 
+#ifdef HAVE_CUSTOM_LOGGER
+#include "custom-logger.hpp"
+#else
+
 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_FATAL is not a level and is logged unconditionally
   LOG_ALL            = 255 // all messages
 };
 
@@ -57,10 +61,7 @@
   bool
   isEnabled(LogLevel level) const
   {
-    // std::cerr << m_moduleName <<
-    //   " enabled = " << m_enabledLogLevel
-    //           << " level = " << level << std::endl;
-    return (m_enabledLogLevel >= level);
+    return m_enabledLogLevel >= level;
   }
 
   void
@@ -140,13 +141,10 @@
 #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)                             \
-do {                                                          \
-  std::clog << ::nfd::Logger::now() << " FATAL: "             \
-            << "[" << g_logger << "] " << expression << "\n"; \
-} while (false)
+#define NFD_LOG_FATAL(expression) NFD_LOG(FATAL, FATAL,   expression)
 
 } // namespace nfd
 
+#endif // HAVE_CUSTOM_LOGGER
+
 #endif // NFD_CORE_LOGGER_HPP