Logging Facility in ndn-cxx

Team: Junxiao Shi, Davide Pesavento, Spyridon Mastorakis, Minsheng Zhang


The ndn-cxx library can benefit from a logging facility. In particular, it’s helpful for debugging application protocols, management modules, and security models.

What it does

This project adds a logging facility into ndn-cxx, and makes use of logging in certain key components, so that it’s easier to debug the ndn-cxx library itself and applications based on this library.

The public API is a series of macros similar to NFD logger. This API is thread-safe which means multiple threads can write logs simultaneously without the danger of log lines getting mixed up. The API can be used not only within ndn-cxx, but also by applications.

How we built it

The public API is borrowed from NFD logger and ns-3 logger.

Internally, we mostly use Boost.Log library, which provides thread-safety without requiring mutex locks. Severity level filtering is customized in a way similar to NFD logger, which is expected to have lower overhead than Boost.Log's native per-channel severity filtering.


Logging initialization Provide a global function to initialize the logger. An std::ostream is passed to this function, and logs are written to this stream. Logs written before this function is called are discarded silently. Application can enable logging by calling this function during its initialization.

Log source organization Provide a macro similar to NFD_LOG_INIT that creates a log source within ndn-cxx. Provide a global function to configure log levels for log sources. This function should take a string as the argument, and the syntax of this function is similar to NS_LOG environment variable. This function should be invoked in the logging initialization function with NDN_CXX_LOG environment variable, and may be called again by application to change log levels.

Log output macro Provide a series of macros similar to NFD_LOG_DEBUG that writes a line of log. These macros can be used within ndn-cxx in any file that has created a log source.

Usage of logging Add logging into ndn-cxx Face, ndn::nfd::Controller, SegmentFetcher classes. Modify ndnping, nfdc, and nfd-status to invoke logging initialization function.

Expected Outcome

Demo: Execute ndnping, nfdc, and nfd-status, show ndn-cxx logging output.

What works

What does not work


Challenges we ran into

Despite many previous attempts by Yumin, Alex, et al, we still face problems to find out the correct linker flags to use Boost.Log library. We were able to track down the exact error by reading Waf log files, and fixed the problem.

Boost.Log is very tricky to use, especially when we try to keep it thread-safe, and provide an API similar to NFD and ns-3 logging. We were able to overcome those limitations by adding customized templates.

What's next for ndn-cxx logging facility