AgIsoStack++
A control-function-focused implementation of the major ISOBUS and J1939 protocols
Loading...
Searching...
No Matches
can_stack_logger.cpp
Go to the documentation of this file.
1//================================================================================================
9//================================================================================================
11
12#include <iostream>
13
14namespace isobus
15{
16 CANStackLogger *CANStackLogger::logger = nullptr;
19
20#ifndef DISABLE_CAN_STACK_LOGGER
21 void CANStackLogger::CAN_stack_log(LoggingLevel level, const std::string &logText)
22 {
23 LOCK_GUARD(Mutex, loggerMutex);
24 CANStackLogger *canStackLogger = nullptr;
25
26 if ((get_can_stack_logger(canStackLogger)) &&
27 (level >= get_log_level()))
28 {
29 canStackLogger->sink_CAN_stack_log(level, logText);
30 }
31 }
32
33 void CANStackLogger::debug(const std::string &logText)
34 {
36 }
37
38 void CANStackLogger::info(const std::string &logText)
39 {
41 }
42
43 void CANStackLogger::warn(const std::string &logText)
44 {
46 }
47
48 void CANStackLogger::error(const std::string &logText)
49 {
51 }
52
53 void CANStackLogger::critical(const std::string &logText)
54 {
56 }
57
58#endif // DISABLE_CAN_STACK_LOGGER
59
61 {
62 logger = logSink;
63 }
64
69
71 {
72 currentLogLevel = newLogLevel;
73 }
74
76 {
77 // Override this function to use the log sink
78 }
79
81 {
82 canStackLogger = logger;
83 return (nullptr != canStackLogger);
84 }
85} // namespace isobus
A class that acts as a logging sink. The intent is that someone could make their own derived class of...
A base class for a CAN logger, used to get diagnostic info from the CAN stack.
virtual void sink_CAN_stack_log(LoggingLevel level, const std::string &logText)
Override this to make a log sink for your application.
static void error(const std::string &logText)
Logs a string to the log sink with Error severity. Wraps sink_CAN_stack_log.
LoggingLevel
Enumerates the various log message severities.
@ Warning
Warnings indicate issues that do not stop normal operation, but should be noted for troubleshooting.
@ Critical
Critical issues are fundamental problems that must be solved for the stack to work properly.
@ Info
General status info messages and messages about how things are working under normal conditions.
@ Error
Errors are issues that interrupt normal operation.
static void info(const std::string &logText)
Logs a string to the log sink with Info severity. Wraps sink_CAN_stack_log.
static Mutex loggerMutex
A mutex that protects the logger so it can be used from multiple threads.
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 LoggingLevel currentLogLevel
The current log level. Logs for levels below the current one will be dropped.
static void set_can_stack_logger_sink(CANStackLogger *logSink)
Assigns a derived logger class to be used as the log sink.
static void debug(const std::string &logText)
Logs a string to the log sink with Debug severity. Wraps sink_CAN_stack_log.
static CANStackLogger * logger
A static pointer to an instance of a logger.
static void critical(const std::string &logText)
Logs a string to the log sink with Critical severity. Wraps sink_CAN_stack_log.
static void set_log_level(LoggingLevel newLogLevel)
Sets the current logging level.
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.
static void warn(const std::string &logText)
Logs a string to the log sink with Warning severity. Wraps sink_CAN_stack_log.
static LoggingLevel get_log_level()
Returns the current logging level.
This namespace encompasses all of the ISO11783 stack's functionality to reduce global namespace pollu...