NDS3  1.0.0
API reference manual
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Logging

Macros

#define ndsLogStream(node, logLevel)   if(!(node).isLogLevelEnabled(logLevel)) {} else (node).getLogger(logLevel)
 If the logging is enabled for the specified severity level then the macro returns the proper logging stream, otherwise it skips the logging operation.
 
#define ndsDebugStream(node)   ndsLogStream(node, nds::logLevel_t::debug)
 Log to the debug stream if the debug log level is enabled on the selected node. More...
 
#define ndsInfoStream(node)   ndsLogStream(node, nds::logLevel_t::info)
 Log to the info stream if the info log level is enabled on the selected node. More...
 
#define ndsWarningStream(node)   ndsLogStream(node, nds::logLevel_t::warning)
 Log to the warning stream if the warning log level is enabled on the selected node. More...
 
#define ndsErrorStream(node)   ndsLogStream(node, nds::logLevel_t::error)
 Log to the error stream if the error log level is enabled on the selected node. More...
 

Enumerations

enum  nds::logLevel_t : std::uint8_t {
  nds::logLevel_t::debug, nds::logLevel_t::info, nds::logLevel_t::warning, nds::logLevel_t::error,
  nds::logLevel_t::none
}
 Defines the severities of the log information. More...
 

Functions

std::ostream & nds::Base::getLogger (const logLevel_t logLevel)
 Retrieve a logging stream for the specified log level. More...
 
bool nds::Base::isLogLevelEnabled (const logLevel_t logLevel) const
 Returns true if the logging for a particular severity level has been enabled. More...
 
void nds::Base::setLogLevel (const logLevel_t logLevel)
 Enable the logging for a particular severity level. More...
 
std::ostream & nds::BaseImpl::getLogger (const logLevel_t logLevel)
 Retrieve a stream that can be used for logging. More...
 
bool nds::BaseImpl::isLogLevelEnabled (const logLevel_t logLevel) const
 Returns true if the logging for a particular severity level has been enabled. More...
 
virtual void nds::BaseImpl::setLogLevel (const logLevel_t logLevel)
 Enable the logging for a particular severity level. More...
 

Detailed Description

The Logging methods can be used to send debug, information, warning or errors to the control system.

The logging interface is control-system agnostic.

Each logged information is tied to a node, and the log level of each node can be set separately. For instance, it is possible to have the whole device (root node) with a log level set to "warning" and only a specific state machine set to "debug".

The logging level of each node can be set with Base::setLogLevel().

Each node provides a different std::ostream object for each severity level and for each thread. Your application can retrieve the std::ostream object by using Base::getLogger().

Warning
Altought it is possible to use directly Base::getLogger() in order to perform the log operations, the suggested method is the usage of the logging macros ndsDebugStream, ndsInfoStream, ndsWarningStream and ndsErrorStream.

The loggin macros boost the performances by avoiding the log altogheter when it is not necessary

Macro Definition Documentation

#define ndsDebugStream (   node)    ndsLogStream(node, nds::logLevel_t::debug)

Log to the debug stream if the debug log level is enabled on the selected node.

The last logged element must be std::endl.

Example:

ndsDebugStream(node) << "The value has been changed from " << value0 << " to value " << value1 << std::endl
#define ndsErrorStream (   node)    ndsLogStream(node, nds::logLevel_t::error)

Log to the error stream if the error log level is enabled on the selected node.

The last logged element must be std::endl.

Example:

ndsErrorStream(node) << "An error has occurred while updating the value to " << value << std::endl
#define ndsInfoStream (   node)    ndsLogStream(node, nds::logLevel_t::info)

Log to the info stream if the info log level is enabled on the selected node.

The last logged element must be std::endl.

Example:

ndsInfoStream(node) << "The value has been changed from " << value0 << " to value " << value1 << std::endl
#define ndsWarningStream (   node)    ndsLogStream(node, nds::logLevel_t::warning)

Log to the warning stream if the warning log level is enabled on the selected node.

The last logged element must be std::endl.

Example:

ndsWarningStream(node) << "The value could not be changed from " << value0 << " to " << value1 << std::endl

Enumeration Type Documentation

enum nds::logLevel_t : std::uint8_t
strong

Defines the severities of the log information.

Enumerator
debug 

Debug information.

info 

Non critical information.

warning 

Warning.

error 

Error.

none 

Nothing is logger.

Function Documentation

std::ostream& nds::BaseImpl::getLogger ( const logLevel_t  logLevel)

Retrieve a stream that can be used for logging.

Logging streams are specific for the requested log level and the current thread.

Parameters
logLevelthe severity level of the messages that will be logged througn the stream
Returns
a logging stream for the requested log level in the current thread
std::ostream& nds::Base::getLogger ( const logLevel_t  logLevel)

Retrieve a logging stream for the specified log level.

You should use the NDS macros ndsDebugStream, ndsInfoStream, ndsWarningStream and ndsErrorStream in order to perform log operations: this increases the performances by avoiding non-necessary operations if the log has been disabled.

The log information must be terminated by std::endl.

Log streams are specific for each running thread in order to avoid multithreading related issues.

Example of usage:

node.getLogger(nds::logLevel_t::warning) << "This is a warning message" << std::endl;

or the preferred way:

ndsWarningStream(node) << "This is the warning n." << 10 << std::endl;
Parameters
logLevelthe level of the messages that will be logged to the stream
Returns
a stream to which your application can send log messages. Log messages must be terminated by std::endl
bool nds::BaseImpl::isLogLevelEnabled ( const logLevel_t  logLevel) const

Returns true if the logging for a particular severity level has been enabled.

Parameters
logLevelthe severity level for which the status is required
Returns
true if the logging for the specified severity level is enabled
bool nds::Base::isLogLevelEnabled ( const logLevel_t  logLevel) const

Returns true if the logging for a particular severity level has been enabled.

Parameters
logLevelthe severity level for which the status is required
Returns
true if the logging for the specified severity level is enabled
virtual void nds::BaseImpl::setLogLevel ( const logLevel_t  logLevel)
virtual

Enable the logging for a particular severity level.

Parameters
logLevelthe severity level for which the logging is enabled.
void nds::Base::setLogLevel ( const logLevel_t  logLevel)

Enable the logging for a particular severity level.

The logging severity level will be set also on the node's children.

Parameters
logLevelthe severity level for which the logging is enabled.