|
JBLogger
|
Logging class. More...
#include <jblogger.h>
Public Member Functions | |
| JBLogger (const char *moduleName, LogLevel level=LogLevel::LOG_LEVEL_WARNING, Stream &stream=Serial, bool showLogLevel=true, bool showModuleName=true, bool showTimestamp=true) | |
| Constructor. | |
| void | log (LogLevel logLevel, bool writePrefix, bool writeLinefeed, const char *message,...) |
| Logs a const char* message with the specified log level. | |
| void | log (LogLevel logLevel, bool writePrefix, bool writeLinefeed, std::string &message,...) |
| Logs a std::string message with the specified log level. | |
| template<class T , typename... Args> | |
| void | error (T message, Args... args) |
| Log a message with the ERROR log level. | |
| template<class T , typename... Args> | |
| void | warning (T message, Args... args) |
| Log a message with the WARNING log level. | |
| template<class T , typename... Args> | |
| void | info (T message, Args... args) |
| Log a message with the INFO log level. | |
| template<class T , typename... Args> | |
| void | debug (T message, Args... args) |
| Log a message with the DEBUG log level. | |
| template<class T , typename... Args> | |
| void | trace (T message, Args... args) |
| Log a message with the TRACE log level. | |
| void | traceDump (const void *buffer, uint32_t size) |
| Log a hex and ASCII dump of a memory buffer with the TRACE log level. | |
| void | traceHexDump (const void *buffer, uint32_t size) |
| Log a hex dump of a memory buffer with the TRACE log level. | |
| void | traceAsciiDump (const void *buffer, uint32_t size) |
| Trace an ASCII dump of a memory buffer. | |
| void | traceBinaryDump (const void *buffer, uint32_t size) |
| Logs a a binary dump of a memory buffer with the TRACE log level. | |
| void | setOutput (Stream &stream) |
| Allows you to specify the output stream for logging. | |
| Stream & | getOutput () |
| Returns the output stream for logging. | |
| void | setLogLevel (LogLevel level) |
| Sets the minimum log level for messages to be logged. | |
| LogLevel | getLogLevel () |
| Returns the minimum log level for messages to be logged. | |
| void | setShowLogLevel (bool value) |
| Specifies whether the log level should be displayed in log messages. | |
| bool | getShowLogLevel () const |
| Returns whether the log level should be displayed in log messages. | |
| void | setShowModuleName (bool value) |
| Specifies whether the module name should be displayed in log messages. | |
| bool | getShowModuleName () const |
| Returns whether the module name should be displayed in log messages. | |
| void | setShowTimestamp (bool value) |
| Specifies whether timestamps should be displayed in log messages. | |
| bool | getShowTimestamp () const |
| Returns whether timestamps should be displayed in log messages. | |
Logging class.
This class is used for logging
Depending on the settings, it will output log messages in the following format:
(timestamp) log_level module_name: message
| JBLogger::JBLogger | ( | const char * | moduleName, |
| LogLevel | level = LogLevel::LOG_LEVEL_WARNING, |
||
| Stream & | stream = Serial, |
||
| bool | showLogLevel = true, |
||
| bool | showModuleName = true, |
||
| bool | showTimestamp = true |
||
| ) |
Constructor.
| moduleName | Module name |
| level | Log level, defaults to LOG_LEVEL_WARNING |
| stream | Stream to log to, defaults to Serial |
| showLogLevel | Show log level in log message, defaults to true |
| showModuleName | Show module name in log message, defaults to true |
| showTimestamp | Show timestamp in log message, defaults to true |
|
inline |
Log a message with the DEBUG log level.
This templated function logs an error message with the specified log level. It allows you to pass a message and additional variadic arguments to format the message.
You can pass a message of any type 'T' supported by overloads of the log() function.
| T | The type of the message parameter. |
| Args | The types of additional variadic arguments. |
| message | The error message, which can be of any type 'T'. |
| args | Additional arguments to be formatted alongside the message. |
|
inline |
Log a message with the ERROR log level.
This templated function logs an error message with the specified log level. It allows you to pass a message and additional variadic arguments to format the message.
You can pass a message of any type 'T' supported by overloads of the log() function.
| T | The type of the message parameter. |
| Args | The types of additional variadic arguments. |
| message | The error message, which can be of any type 'T'. |
| args | Additional arguments to be formatted alongside the message. |
| LogLevel JBLogger::getLogLevel | ( | ) |
Returns the minimum log level for messages to be logged.
| Stream & JBLogger::getOutput | ( | ) |
Returns the output stream for logging.
| bool JBLogger::getShowLogLevel | ( | ) | const |
Returns whether the log level should be displayed in log messages.
| bool JBLogger::getShowModuleName | ( | ) | const |
Returns whether the module name should be displayed in log messages.
| bool JBLogger::getShowTimestamp | ( | ) | const |
Returns whether timestamps should be displayed in log messages.
|
inline |
Log a message with the INFO log level.
This templated function logs an error message with the specified log level. It allows you to pass a message and additional variadic arguments to format the message.
You can pass a message of any type 'T' supported by overloads of the log() function.
| T | The type of the message parameter. |
| Args | The types of additional variadic arguments. |
| message | The error message, which can be of any type 'T'. |
| args | Additional arguments to be formatted alongside the message. |
| void JBLogger::log | ( | LogLevel | logLevel, |
| bool | writePrefix, | ||
| bool | writeLinefeed, | ||
| const char * | message, | ||
| ... | |||
| ) |
Logs a const char* message with the specified log level.
This function logs a message with the given log level. It supports various options like specifying whether the message is a part of a larger message, whether to write a line feed after the message, and allows for variadic arguments to format the message.
| logLevel | The log level to use for the message. |
| writePrefix | Indicates whether to write the prefix before each message. |
| writeLinefeed | Specifies whether to write a line feed after the message. |
| message | The format string for the message, with optional format specifiers. |
| ... | Variadic arguments to be formatted according to the format string. |
| void JBLogger::log | ( | LogLevel | logLevel, |
| bool | writePrefix, | ||
| bool | writeLinefeed, | ||
| std::string & | message, | ||
| ... | |||
| ) |
Logs a std::string message with the specified log level.
This function logs a message with the given log level. It supports various options like specifying whether the message is a part of a larger message, whether to write a line feed after the message, and allows for variadic arguments to format the message.
| logLevel | The log level to use for the message. |
| writePrefix | Indicates whether to write the prefix before each message. |
| writeLinefeed | Specifies whether to write a line feed after the message. |
| message | The format string for the message, with optional format specifiers. |
| ... | Variadic arguments to be formatted according to the format string. |
| void JBLogger::setLogLevel | ( | LogLevel | level | ) |
Sets the minimum log level for messages to be logged.
This function allows you to specify the minimum log level for messages to be logged. Messages with a log level equal to or higher than the specified level will be logged, while messages with lower log levels will be ignored.
| level | The minimum log level to be logged. |
| void JBLogger::setOutput | ( | Stream & | stream | ) |
Allows you to specify the output stream for logging.
This function allows you to specify an output stream for logging. The output stream should be an instance of a class that inherits from the Stream class. It is used to define where the log messages will be sent.
| stream | A reference to the output stream where log messages will be written. |
| void JBLogger::setShowLogLevel | ( | bool | value | ) |
Specifies whether the log level should be displayed in log messages.
This function allows you to control whether the log level should be included in the log messages. If set to true, the log level will be displayed in log messages. If set to false, the log level will not be included in the log messages.
| value | A boolean value indicating whether to show the log level in log messages. |
| void JBLogger::setShowModuleName | ( | bool | value | ) |
Specifies whether the module name should be displayed in log messages.
This function allows you to control whether the module name should be included in the log messages. If set to true, the module name will be displayed in log messages. If set to false, the module name will not be included in the log messages.
| value | A boolean value indicating whether to show the module name in log messages. |
| void JBLogger::setShowTimestamp | ( | bool | value | ) |
Specifies whether timestamps should be displayed in log messages.
Set whether to display timestamps in log messages.
This function allows you to control whether timestamps should be included in the log messages. If set to true, timestamps will be displayed in log messages to indicate when each log entry was generated. If set to false, timestamps will not be included in the log messages.
| value | A boolean value indicating whether to show timestamps in log messages. |
|
inline |
Log a message with the TRACE log level.
This templated function logs an error message with the specified log level. It allows you to pass a message and additional variadic arguments to format the message.
You can pass a message of any type 'T' supported by overloads of the log() function.
| T | The type of the message parameter. |
| Args | The types of additional variadic arguments. |
| message | The error message, which can be of any type 'T'. |
| args | Additional arguments to be formatted alongside the message. |
| void JBLogger::traceAsciiDump | ( | const void * | buffer, |
| uint32_t | size | ||
| ) |
Trace an ASCII dump of a memory buffer.
This method traces an ASCII dump of a memory buffer to the log output. It takes a pointer to the memory buffer and the size of the buffer to perform the dump.
| buffer | A pointer to the memory buffer to be dumped. |
| size | The size (in bytes) of the memory buffer. |
| void JBLogger::traceBinaryDump | ( | const void * | buffer, |
| uint32_t | size | ||
| ) |
Logs a a binary dump of a memory buffer with the TRACE log level.
This function writes a binary dump of a memory buffer to the log output. It takes a pointer to the memory buffer and the size of the buffer to perform the dump.
| buffer | A pointer to the memory buffer to be dumped. |
| size | The size (in bytes) of the memory buffer. |
| void JBLogger::traceDump | ( | const void * | buffer, |
| uint32_t | size | ||
| ) |
Log a hex and ASCII dump of a memory buffer with the TRACE log level.
This function writes a hexadecimal and ASCII dump of a memory buffer to the log It takes a pointer to the memory buffer and the size of the buffer to perform the dump.
The dump is grouped into 16 byte rows, with the hexadecimal dump on the left and the ASCII dump on the right.
| buffer | A pointer to the memory buffer to be dumped. |
| size | The size (in bytes) of the memory buffer. |
| void JBLogger::traceHexDump | ( | const void * | buffer, |
| uint32_t | size | ||
| ) |
Log a hex dump of a memory buffer with the TRACE log level.
This function writes a hexadecimal dump of a memory buffer to the log output. It takes output. It takes a pointer to the memory buffer and the size of the buffer to perform the dump.
| buffer | A pointer to the memory buffer to be dumped. |
| size | The size (in bytes) of the memory buffer. |
|
inline |
Log a message with the WARNING log level.
This templated function logs an error message with the specified log level. It allows you to pass a message and additional variadic arguments to format the message.
You can pass a message of any type 'T' supported by overloads of the log() function.
| T | The type of the message parameter. |
| Args | The types of additional variadic arguments. |
| message | The error message, which can be of any type 'T'. |
| args | Additional arguments to be formatted alongside the message. |