AgIsoStack++
A control-function-focused implementation of the major ISOBUS and J1939 protocols
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Static Private Member Functions | Static Private Attributes | List of all members
isobus::CANStackLogger Class Reference

A base class for a CAN logger, used to get diagnostic info from the CAN stack. More...

#include <can_stack_logger.hpp>

Collaboration diagram for isobus::CANStackLogger:
[legend]

Public Types

enum class  LoggingLevel {
  Debug = 0 , Info , Warning , Error ,
  Critical
}
 Enumerates the various log message severities. More...
 

Public Member Functions

 CANStackLogger ()=default
 The constructor for a CANStackLogger.
 
 ~CANStackLogger ()=default
 The destructor for a CANStackLogger.
 
virtual void sink_CAN_stack_log (LoggingLevel level, const std::string &logText)
 Override this to make a log sink for your application.
 

Static Public Member Functions

static void CAN_stack_log (LoggingLevel level, const std::string &logText)
 Gets called from the CAN stack to log information. Wraps sink_CAN_stack_log.
 
template<typename... Args>
static void CAN_stack_log (LoggingLevel level, const std::string &format, Args... args)
 Gets called from the CAN stack to log information. Wraps sink_CAN_stack_log.
 
static void debug (const std::string &logText)
 Logs a string to the log sink with Debug severity. Wraps sink_CAN_stack_log.
 
template<typename... Args>
static void debug (const std::string &format, Args... args)
 Logs a printf formatted string to the log sink with Debug severity. Wraps sink_CAN_stack_log.
 
static void info (const std::string &logText)
 Logs a string to the log sink with Info severity. Wraps sink_CAN_stack_log.
 
template<typename... Args>
static void info (const std::string &format, Args... args)
 Logs a printf formatted string to the log sink with Info severity. Wraps sink_CAN_stack_log.
 
static void warn (const std::string &logText)
 Logs a string to the log sink with Warning severity. Wraps sink_CAN_stack_log.
 
template<typename... Args>
static void warn (const std::string &format, Args... args)
 Logs a printf formatted string to the log sink with Warning severity. Wraps sink_CAN_stack_log.
 
static void error (const std::string &logText)
 Logs a string to the log sink with Error severity. Wraps sink_CAN_stack_log.
 
template<typename... Args>
static void error (const std::string &format, Args... args)
 Logs a printf formatted string to the log sink with Error severity. Wraps sink_CAN_stack_log.
 
static void critical (const std::string &logText)
 Logs a string to the log sink with Critical severity. Wraps sink_CAN_stack_log.
 
template<typename... Args>
static void critical (const std::string &format, Args... args)
 Logs a printf formatted string to the log sink with Critical severity. Wraps sink_CAN_stack_log.
 
static void set_can_stack_logger_sink (CANStackLogger *logSink)
 Assigns a derived logger class to be used as the log sink.
 
static LoggingLevel get_log_level ()
 Returns the current logging level.
 
static void set_log_level (LoggingLevel newLogLevel)
 Sets the current logging level.
 

Static Private Member Functions

static bool get_can_stack_logger (CANStackLogger *&canStackLogger)
 Provides a pointer to the static instance of the logger, and returns if the pointer is valid.
 

Static Private Attributes

static CANStackLoggerlogger = nullptr
 A static pointer to an instance of a logger.
 
static LoggingLevel currentLogLevel = LoggingLevel::Info
 The current log level. Logs for levels below the current one will be dropped.
 
static Mutex loggerMutex
 A mutex that protects the logger so it can be used from multiple threads.
 

Detailed Description

A base class for a CAN logger, used to get diagnostic info from the CAN stack.

The CAN stack prints helpful text that may inform you of issues in either the stack or your application. You can override a function in this class to begin consuming this logging text.

Definition at line 28 of file can_stack_logger.hpp.

Member Enumeration Documentation

◆ LoggingLevel

Enumerates the various log message severities.

Enumerator
Debug 

Verbose information.

Info 

General status info messages and messages about how things are working under normal conditions.

Warning 

Warnings indicate issues that do not stop normal operation, but should be noted for troubleshooting.

Error 

Errors are issues that interrupt normal operation.

Critical 

Critical issues are fundamental problems that must be solved for the stack to work properly.

Definition at line 32 of file can_stack_logger.hpp.

Member Function Documentation

◆ CAN_stack_log() [1/2]

template<typename... Args>
static void isobus::CANStackLogger::CAN_stack_log ( LoggingLevel level,
const std::string & format,
Args... args )
inlinestatic

Gets called from the CAN stack to log information. Wraps sink_CAN_stack_log.

Parameters
[in]levelThe log level for this text
[in]formatA format string of text to log, similar to printf
[in]argsA list of printf style arguments to use with the format string when logging

Definition at line 59 of file can_stack_logger.hpp.

Here is the call graph for this function:

◆ CAN_stack_log() [2/2]

void isobus::CANStackLogger::CAN_stack_log ( LoggingLevel level,
const std::string & logText )
static

Gets called from the CAN stack to log information. Wraps sink_CAN_stack_log.

Parameters
[in]levelThe log level for this text
[in]logTextThe text to be logged

Definition at line 21 of file can_stack_logger.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ critical() [1/2]

template<typename... Args>
static void isobus::CANStackLogger::critical ( const std::string & format,
Args... args )
inlinestatic

Logs a printf formatted string to the log sink with Critical severity. Wraps sink_CAN_stack_log.

Parameters
[in]formatThe format string, similar to printf
[in]argsThe variadic arguments to format, similar to printf

Definition at line 135 of file can_stack_logger.hpp.

Here is the call graph for this function:

◆ critical() [2/2]

void isobus::CANStackLogger::critical ( const std::string & logText)
static

Logs a string to the log sink with Critical severity. Wraps sink_CAN_stack_log.

Parameters
[in]logTextThe text to be logged at Critical severity

Definition at line 53 of file can_stack_logger.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ debug() [1/2]

template<typename... Args>
static void isobus::CANStackLogger::debug ( const std::string & format,
Args... args )
inlinestatic

Logs a printf formatted string to the log sink with Debug severity. Wraps sink_CAN_stack_log.

Parameters
[in]formatThe format string, similar to printf
[in]argsThe variadic arguments to format, similar to printf

Definition at line 83 of file can_stack_logger.hpp.

Here is the call graph for this function:

◆ debug() [2/2]

void isobus::CANStackLogger::debug ( const std::string & logText)
static

Logs a string to the log sink with Debug severity. Wraps sink_CAN_stack_log.

Parameters
[in]logTextThe text to be logged at Debug severity

Definition at line 33 of file can_stack_logger.cpp.

Here is the call graph for this function:

◆ error() [1/2]

template<typename... Args>
static void isobus::CANStackLogger::error ( const std::string & format,
Args... args )
inlinestatic

Logs a printf formatted string to the log sink with Error severity. Wraps sink_CAN_stack_log.

Parameters
[in]formatThe format string, similar to printf
[in]argsThe variadic arguments to format, similar to printf

Definition at line 122 of file can_stack_logger.hpp.

Here is the call graph for this function:

◆ error() [2/2]

void isobus::CANStackLogger::error ( const std::string & logText)
static

Logs a string to the log sink with Error severity. Wraps sink_CAN_stack_log.

Parameters
[in]logTextThe text to be logged at Error severity

Definition at line 48 of file can_stack_logger.cpp.

Here is the call graph for this function:

◆ get_can_stack_logger()

bool isobus::CANStackLogger::get_can_stack_logger ( CANStackLogger *& canStackLogger)
staticprivate

Provides a pointer to the static instance of the logger, and returns if the pointer is valid.

Parameters
[out]canStackLoggerThe static logger instance
Returns
true if the logger is not nullptr or false if it is nullptr

Definition at line 80 of file can_stack_logger.cpp.

Here is the caller graph for this function:

◆ get_log_level()

CANStackLogger::LoggingLevel isobus::CANStackLogger::get_log_level ( )
static

Returns the current logging level.

Log statements below the current level will be dropped and not passed to the log sink

Returns
The current log level

Definition at line 65 of file can_stack_logger.cpp.

Here is the caller graph for this function:

◆ info() [1/2]

template<typename... Args>
static void isobus::CANStackLogger::info ( const std::string & format,
Args... args )
inlinestatic

Logs a printf formatted string to the log sink with Info severity. Wraps sink_CAN_stack_log.

Parameters
[in]formatThe format string, similar to printf
[in]argsThe variadic arguments to format, similar to printf

Definition at line 96 of file can_stack_logger.hpp.

Here is the call graph for this function:

◆ info() [2/2]

void isobus::CANStackLogger::info ( const std::string & logText)
static

Logs a string to the log sink with Info severity. Wraps sink_CAN_stack_log.

Parameters
[in]logTextThe text to be logged at Info severity

Definition at line 38 of file can_stack_logger.cpp.

Here is the call graph for this function:

◆ set_can_stack_logger_sink()

void isobus::CANStackLogger::set_can_stack_logger_sink ( CANStackLogger * logSink)
static

Assigns a derived logger class to be used as the log sink.

Parameters
[in]logSinkA pointer to a derived CANStackLogger class

Definition at line 60 of file can_stack_logger.cpp.

◆ set_log_level()

void isobus::CANStackLogger::set_log_level ( LoggingLevel newLogLevel)
static

Sets the current logging level.

Log statements below the new level will be dropped and not passed to the log sink

Parameters
[in]newLogLevelThe new logging level

Definition at line 70 of file can_stack_logger.cpp.

◆ sink_CAN_stack_log()

void isobus::CANStackLogger::sink_CAN_stack_log ( LoggingLevel level,
const std::string & logText )
virtual

Override this to make a log sink for your application.

Parameters
[in]levelThe severity level of the log text
[in]logTextThe information being logged

Definition at line 75 of file can_stack_logger.cpp.

Here is the caller graph for this function:

◆ warn() [1/2]

template<typename... Args>
static void isobus::CANStackLogger::warn ( const std::string & format,
Args... args )
inlinestatic

Logs a printf formatted string to the log sink with Warning severity. Wraps sink_CAN_stack_log.

Parameters
[in]formatThe format string, similar to printf
[in]argsThe variadic arguments to format, similar to printf

Definition at line 109 of file can_stack_logger.hpp.

Here is the call graph for this function:

◆ warn() [2/2]

void isobus::CANStackLogger::warn ( const std::string & logText)
static

Logs a string to the log sink with Warning severity. Wraps sink_CAN_stack_log.

Parameters
[in]logTextThe text to be logged at Warning severity

Definition at line 43 of file can_stack_logger.cpp.

Here is the call graph for this function:

Member Data Documentation

◆ currentLogLevel

CANStackLogger::LoggingLevel isobus::CANStackLogger::currentLogLevel = LoggingLevel::Info
staticprivate

The current log level. Logs for levels below the current one will be dropped.

Definition at line 170 of file can_stack_logger.hpp.

◆ logger

CANStackLogger * isobus::CANStackLogger::logger = nullptr
staticprivate

A static pointer to an instance of a logger.

Definition at line 169 of file can_stack_logger.hpp.

◆ loggerMutex

Mutex isobus::CANStackLogger::loggerMutex
staticprivate

A mutex that protects the logger so it can be used from multiple threads.

Definition at line 171 of file can_stack_logger.hpp.


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