22 #ifndef NDN_CXX_UTIL_LOGGER_HPP 
   23 #define NDN_CXX_UTIL_LOGGER_HPP 
   27 #ifdef HAVE_NDN_CXX_CUSTOM_LOGGER 
   28 #include "ndn-cxx/util/custom-logger.hpp" 
   31 #include <boost/log/common.hpp> 
   32 #include <boost/log/expressions/keyword.hpp> 
   33 #include <boost/log/sources/severity_logger.hpp> 
   67 BOOST_LOG_ATTRIBUTE_KEYWORD(module, 
"Module", std::string)
 
   68 BOOST_LOG_ATTRIBUTE_KEYWORD(severity, 
"Severity", 
LogLevel)
 
   77 class Logger : 
public boost::log::sources::severity_logger_mt<LogLevel>
 
   95     return m_currentLevel.load(std::memory_order_relaxed) >= level;
 
  101     m_currentLevel.store(level, std::memory_order_relaxed);
 
  105   const std::string m_moduleName;
 
  106   std::atomic<LogLevel> m_currentLevel;
 
  113 struct ExtractArgument;
 
  115 template<
class T, 
class U>
 
  116 struct ExtractArgument<T(U&)>
 
  121 template<
class T, 
class U>
 
  122 struct ExtractArgument<T(U)&>
 
  128 using ArgumentType = 
typename ExtractArgument<T>::type;
 
  135 #define NDN_LOG_REGISTER_NAME(name) \ 
  137     ::ndn::util::Logger::registerModuleName(BOOST_STRINGIZE(name)); \ 
  142 #define NDN_LOG_INIT_FUNCTION_BODY(name) \ 
  144     static ::ndn::util::Logger logger(BOOST_STRINGIZE(name)); \ 
  163 #define NDN_LOG_INIT(name) \ 
  165     const bool ndn_cxx_loggerRegistration __attribute__((used)) = NDN_LOG_REGISTER_NAME(name); \ 
  166     ::ndn::util::Logger& ndn_cxx_getLogger() \ 
  167     NDN_LOG_INIT_FUNCTION_BODY(name) \ 
  169   struct ndn_cxx_allow_trailing_semicolon 
  181 #define NDN_LOG_MEMBER_DECL() \ 
  182   static ::ndn::util::Logger& ndn_cxx_getLogger(); \ 
  184   static const bool ndn_cxx_loggerRegistration 
  198 #define NDN_LOG_MEMBER_INIT(cls, name) \ 
  199   const bool ::ndn::util::detail::ArgumentType<void(cls&)>::ndn_cxx_loggerRegistration = \ 
  200   NDN_LOG_REGISTER_NAME(name); \ 
  201   ::ndn::util::Logger& ::ndn::util::detail::ArgumentType<void(cls&)>::ndn_cxx_getLogger() \ 
  202   NDN_LOG_INIT_FUNCTION_BODY(name) \ 
  203   struct ndn_cxx_allow_trailing_semicolon 
  209 #define NDN_LOG_MEMBER_DECL_SPECIALIZED(cls) \ 
  211   const bool ::ndn::util::detail::ArgumentType<void(cls&)>::ndn_cxx_loggerRegistration; \ 
  213   ::ndn::util::Logger& ::ndn::util::detail::ArgumentType<void(cls&)>::ndn_cxx_getLogger() 
  226 #define NDN_LOG_MEMBER_INIT_SPECIALIZED(cls, name) \ 
  228   const bool ::ndn::util::detail::ArgumentType<void(cls&)>::ndn_cxx_loggerRegistration = \ 
  229   NDN_LOG_REGISTER_NAME(name); \ 
  231   ::ndn::util::Logger& ::ndn::util::detail::ArgumentType<void(cls&)>::ndn_cxx_getLogger() \ 
  232   NDN_LOG_INIT_FUNCTION_BODY(name) \ 
  233   struct ndn_cxx_allow_trailing_semicolon 
  237 #define NDN_LOG_INTERNAL(lvl, expression) \ 
  239     if (ndn_cxx_getLogger().isLevelEnabled(::ndn::util::LogLevel::lvl)) { \ 
  240       BOOST_LOG_SEV(ndn_cxx_getLogger(), ::ndn::util::LogLevel::lvl)  \ 
  249 #define NDN_LOG_TRACE(expression) NDN_LOG_INTERNAL(TRACE, expression) 
  254 #define NDN_LOG_DEBUG(expression) NDN_LOG_INTERNAL(DEBUG, expression) 
  259 #define NDN_LOG_INFO(expression) NDN_LOG_INTERNAL(INFO, expression) 
  264 #define NDN_LOG_WARN(expression) NDN_LOG_INTERNAL(WARN, expression) 
  269 #define NDN_LOG_ERROR(expression) NDN_LOG_INTERNAL(ERROR, expression) 
  274 #define NDN_LOG_FATAL(expression) NDN_LOG_INTERNAL(FATAL, expression) 
Represents a log module in the logging facility.
 
bool isLevelEnabled(LogLevel level) const
 
static void registerModuleName(const char *name)
 
const std::string & getModuleName() const
 
void setLevel(LogLevel level)
 
Common includes and macros used throughout the library.
 
std::ostream & operator<<(std::ostream &os, LogLevel level)
Output LogLevel as a string.
 
LogLevel parseLogLevel(const std::string &s)
Parse LogLevel from a string.
 
LogLevel
Indicates the severity level of a log message.
 
@ FATAL
fatal (will be logged unconditionally)
 
@ TRACE
trace messages (most verbose)
 
@ INFO
informational messages
 
@ ERROR
serious error messages