ndn::util::Logging Class Reference

Controls the logging facility. More...

#include <ndn-cxx/util/logging.hpp>

+ Inheritance diagram for ndn::util::Logging:
+ Collaboration diagram for ndn::util::Logging:

Static Public Member Functions

static void flush ()
 Flush log backend. More...
 
static std::set< std::string > getLoggerNames ()
 Get list of all registered logger names. More...
 
static boost::shared_ptr< boost::log::sinks::sink > makeDefaultStreamDestination (shared_ptr< std::ostream > os, bool wantAutoFlush=true)
 Create stream log destination using default formatting. More...
 
static void setDestination (boost::shared_ptr< boost::log::sinks::sink > destination)
 Set or replace log destination. More...
 
static void setDestination (std::ostream &os, bool wantAutoFlush)
 Helper method to set stream log destination. More...
 
static void setLevel (const std::string &config)
 Set severity levels with a config string. More...
 
static void setLevel (const std::string &prefix, LogLevel level)
 Set severity level. More...
 

Detailed Description

Controls the logging facility.

Note
Public static methods are thread safe. Non-public methods are not guaranteed to be thread safe.

Definition at line 46 of file logging.hpp.

Member Function Documentation

◆ flush()

void ndn::util::Logging::flush ( )
inlinestatic

Flush log backend.

This ensures all log messages are written to the destination stream.

Definition at line 218 of file logging.hpp.

◆ getLoggerNames()

std::set< std::string > ndn::util::Logging::getLoggerNames ( )
inlinestatic

Get list of all registered logger names.

Definition at line 194 of file logging.hpp.

◆ makeDefaultStreamDestination()

boost::shared_ptr< boost::log::sinks::sink > ndn::util::Logging::makeDefaultStreamDestination ( shared_ptr< std::ostream >  os,
bool  wantAutoFlush = true 
)
static

Create stream log destination using default formatting.

Definition at line 273 of file logging.cpp.

◆ setDestination() [1/2]

void ndn::util::Logging::setDestination ( boost::shared_ptr< boost::log::sinks::sink >  destination)
inlinestatic

Set or replace log destination.

Parameters
destinationlog backend, e.g., returned by makeDefaultStreamDestination()

The initial destination is std::clog.

Note that if destination is nullptr, the destination will be removed and the application is expected to add its own. If the application does not set a custom destination (using this function or directly using Boost.Log routines), the default Boost.Log destination will be used. Refer to Boost.Log documentation and source code for details.

Definition at line 212 of file logging.hpp.

◆ setDestination() [2/2]

void ndn::util::Logging::setDestination ( std::ostream &  os,
bool  wantAutoFlush 
)
static

Helper method to set stream log destination.

Parameters
osa stream for log output; caller must ensure it remains valid until setDestination() is invoked again or program exits
wantAutoFlushif true, the created logging sink will be auto-flushed

This is equivalent to setDestination(makeDefaultStreamDestination(shared_ptr<std::ostream>(&os, nullDeleter))).

Definition at line 249 of file logging.cpp.

◆ setLevel() [1/2]

void ndn::util::Logging::setLevel ( const std::string &  config)
inlinestatic

Set severity levels with a config string.

Parameters
configcolon-separated key=value pairs
Exceptions
std::invalid_argumentconfig string is malformed
Logging::setLevel("*=INFO:Face=DEBUG:NfdController=WARN");
static void setLevel(const std::string &prefix, LogLevel level)
Set severity level.
Definition: logging.hpp:200

is equivalent to:

@ WARN
warning messages
@ INFO
informational messages
@ DEBUG
debug messages

Definition at line 206 of file logging.hpp.

◆ setLevel() [2/2]

void ndn::util::Logging::setLevel ( const std::string &  prefix,
LogLevel  level 
)
inlinestatic

Set severity level.

Parameters
prefixlogger prefix; this can be a specific logger name, a general prefix like "ndn.a.*" to apply a setting for all modules that contain that prefix, or "*" for all modules
levelminimum severity level

Log messages are output only if their severity is greater than the current minimum severity level. The initial severity level is LogLevel::NONE, which enables FATAL messages only.

Definition at line 200 of file logging.hpp.