Public Types | Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
uavcan::Logger Class Reference

#include <logger.hpp>

Public Types

typedef ILogSink::LogLevel LogLevel
 

Public Member Functions

ILogSinkgetExternalSink () const
 
LogLevel getLevel () const
 
MonotonicDuration getTxTimeout () const
 
int init (const TransferPriority priority=TransferPriority::Lowest)
 
int log (const protocol::debug::LogMessage &message)
 
 Logger (INode &node)
 
void setExternalSink (ILogSink *sink)
 
void setLevel (LogLevel level)
 
void setTxTimeout (MonotonicDuration val)
 
template<typename... Args>
int log (LogLevel level, const char *source, const char *format, Args... args) UAVCAN_NOEXCEPT
 
template<typename... Args>
int logDebug (const char *source, const char *format, Args... args) UAVCAN_NOEXCEPT
 
template<typename... Args>
int logInfo (const char *source, const char *format, Args... args) UAVCAN_NOEXCEPT
 
template<typename... Args>
int logWarning (const char *source, const char *format, Args... args) UAVCAN_NOEXCEPT
 
template<typename... Args>
int logError (const char *source, const char *format, Args... args) UAVCAN_NOEXCEPT
 

Static Public Member Functions

static LogLevel getLogLevelAboveAll ()
 

Private Types

enum  { DefaultTxTimeoutMs = 2000 }
 

Private Member Functions

LogLevel getExternalSinkLevel () const
 

Private Attributes

ILogSinkexternal_sink_
 
LogLevel level_
 
Publisher< protocol::debug::LogMessage > logmsg_pub_
 
protocol::debug::LogMessage msg_buf_
 

Detailed Description

Node logging convenience class.

This class is based on the standard UAVCAN message type for logging - uavcan.protocol.debug.LogMessage.

Provides logging methods of different severity; implements two sinks for the log messages:

For each sink an individual severity threshold filter can be configured.

Definition at line 58 of file logger.hpp.

Member Typedef Documentation

◆ LogLevel

Definition at line 61 of file logger.hpp.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
private
Enumerator
DefaultTxTimeoutMs 

Definition at line 70 of file logger.hpp.

Constructor & Destructor Documentation

◆ Logger()

uavcan::Logger::Logger ( INode node)
inlineexplicit

Definition at line 83 of file logger.hpp.

Member Function Documentation

◆ getExternalSink()

ILogSink* uavcan::Logger::getExternalSink ( ) const
inline

External log sink allows the application to install a hook on the logger output. This can be used for application-wide logging. Null pointer means that there's no log sink (can be used to remove it). By default there's no log sink.

Definition at line 147 of file logger.hpp.

◆ getExternalSinkLevel()

LogLevel uavcan::Logger::getExternalSinkLevel ( ) const
inlineprivate

Definition at line 77 of file logger.hpp.

◆ getLevel()

LogLevel uavcan::Logger::getLevel ( ) const
inline

Severity filter for UAVCAN broadcasting. Log message will be broadcasted via the UAVCAN network only if its severity is >= getLevel(). This does not affect the external sink. Default level is ERROR.

Definition at line 138 of file logger.hpp.

◆ getLogLevelAboveAll()

static LogLevel uavcan::Logger::getLogLevelAboveAll ( )
inlinestatic

This value is higher than any valid severity value. Use it to completely suppress the output.

Definition at line 67 of file logger.hpp.

◆ getTxTimeout()

MonotonicDuration uavcan::Logger::getTxTimeout ( ) const
inline

Log message broadcast transmission timeout. The default value should be acceptable for any use case.

Definition at line 154 of file logger.hpp.

◆ init()

int uavcan::Logger::init ( const TransferPriority  priority = TransferPriority::Lowest)
inline

Initializes the logger, does not perform any network activity. Must be called once before use. Returns negative error code.

Definition at line 97 of file logger.hpp.

◆ log() [1/2]

int uavcan::Logger::log ( const protocol::debug::LogMessage &  message)
inline

Logs one message. Please consider using helper methods instead of this one.

The message will be broadcasted via the UAVCAN bus if the severity level of the message is >= severity level of the logger.

The message will be reported into the external log sink if the external sink is installed and the severity level of the message is >= severity level of the external sink.

Returns negative error code.

Definition at line 118 of file logger.hpp.

◆ log() [2/2]

template<typename... Args>
int uavcan::Logger::log ( LogLevel  level,
const char *  source,
const char *  format,
Args...  args 
)

Helper methods for various severity levels and with formatting support. These methods build a formatted log message and pass it into the method log().

Format string usage is a bit unusual: use "%*" for any argument type, use "%%" to print a percent character. No other formating options are supported. Insufficient/extra arguments are ignored.

Example format string: "What do you get if you %* %* by %*? %*. Extra arguments: %* %* %%" ...with the following arguments: "multiply", 6, 9.0F 4.2e1 ...will likely produce this (floating point representation is platform dependent): "What do you get if you multiply 6 by 9.000000? 42.000000. Extra arguments: %* %* %"

Formatting is not supported in C++03 mode.

Definition at line 257 of file logger.hpp.

◆ logDebug()

template<typename... Args>
int uavcan::Logger::logDebug ( const char *  source,
const char *  format,
Args...  args 
)
inline

Definition at line 180 of file logger.hpp.

◆ logError()

template<typename... Args>
int uavcan::Logger::logError ( const char *  source,
const char *  format,
Args...  args 
)
inline

Definition at line 198 of file logger.hpp.

◆ logInfo()

template<typename... Args>
int uavcan::Logger::logInfo ( const char *  source,
const char *  format,
Args...  args 
)
inline

Definition at line 186 of file logger.hpp.

◆ logWarning()

template<typename... Args>
int uavcan::Logger::logWarning ( const char *  source,
const char *  format,
Args...  args 
)
inline

Definition at line 192 of file logger.hpp.

◆ setExternalSink()

void uavcan::Logger::setExternalSink ( ILogSink sink)
inline

Definition at line 148 of file logger.hpp.

◆ setLevel()

void uavcan::Logger::setLevel ( LogLevel  level)
inline

Definition at line 139 of file logger.hpp.

◆ setTxTimeout()

void uavcan::Logger::setTxTimeout ( MonotonicDuration  val)
inline

Definition at line 155 of file logger.hpp.

Member Data Documentation

◆ external_sink_

ILogSink* uavcan::Logger::external_sink_
private

Definition at line 75 of file logger.hpp.

◆ level_

LogLevel uavcan::Logger::level_
private

Definition at line 74 of file logger.hpp.

◆ logmsg_pub_

Publisher<protocol::debug::LogMessage> uavcan::Logger::logmsg_pub_
private

Definition at line 72 of file logger.hpp.

◆ msg_buf_

protocol::debug::LogMessage uavcan::Logger::msg_buf_
private

Definition at line 73 of file logger.hpp.


The documentation for this class was generated from the following file:


uavcan_communicator
Author(s):
autogenerated on Fri Dec 13 2024 03:10:04