22 #ifndef NDN_UTIL_LOGGER_HPP 23 #define NDN_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/sources/logger.hpp> 68 class Logger :
public boost::log::sources::logger_mt
75 registerModuleName(
const char* name);
86 return m_currentLevel.load(std::memory_order_relaxed) >= level;
92 m_currentLevel.store(level, std::memory_order_relaxed);
96 const std::string m_moduleName;
97 std::atomic<LogLevel> m_currentLevel;
119 struct ExtractArgument;
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 236 #if BOOST_VERSION == 105900 238 #define NDN_BOOST_LOG(x) BOOST_LOG(x) << "" 240 #define NDN_BOOST_LOG(x) BOOST_LOG(x) 244 #define NDN_LOG_INTERNAL(lvl, lvlstr, expression) \ 246 if (ndn_cxx_getLogger().isLevelEnabled(::ndn::util::LogLevel::lvl)) { \ 247 NDN_BOOST_LOG(ndn_cxx_getLogger()) << ::ndn::util::detail::LoggerTimestamp{} \ 248 << " " BOOST_STRINGIZE(lvlstr) ": [" << ndn_cxx_getLogger().getModuleName() << "] " \ 257 #define NDN_LOG_TRACE(expression) NDN_LOG_INTERNAL(TRACE, TRACE, expression) 262 #define NDN_LOG_DEBUG(expression) NDN_LOG_INTERNAL(DEBUG, DEBUG, expression) 267 #define NDN_LOG_INFO(expression) NDN_LOG_INTERNAL(INFO, INFO, expression) 272 #define NDN_LOG_WARN(expression) NDN_LOG_INTERNAL(WARN, WARNING, expression) 277 #define NDN_LOG_ERROR(expression) NDN_LOG_INTERNAL(ERROR, ERROR, expression) 282 #define NDN_LOG_FATAL(expression) NDN_LOG_INTERNAL(FATAL, FATAL, expression) 287 #endif // HAVE_NDN_CXX_CUSTOM_LOGGER 289 #endif // NDN_UTIL_LOGGER_HPP
trace messages (most verbose)
std::ostream & operator<<(std::ostream &os, LogLevel level)
Output LogLevel as a string.
LogLevel
Indicates the severity level of a log message.
import common constructs for ndn-cxx library internal use
LogLevel parseLogLevel(const std::string &s)
Parse LogLevel from a string.
A tag type used to output a timestamp to a stream.
Represents a log module in the logging facility.
fatal (will be logged unconditionally)
const std::string & getModuleName() const
void setLevel(LogLevel level)
bool isLevelEnabled(LogLevel level) const