JBLogger
Loading...
Searching...
No Matches
JBLogger Class Reference

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.
 

Detailed Description

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

Constructor & Destructor Documentation

◆ JBLogger()

JBLogger::JBLogger ( const char *  moduleName,
LogLevel  level = LogLevel::LOG_LEVEL_WARNING,
Stream &  stream = Serial,
bool  showLogLevel = true,
bool  showModuleName = true,
bool  showTimestamp = true 
)

Constructor.

Parameters
moduleNameModule name
levelLog level, defaults to LOG_LEVEL_WARNING
streamStream to log to, defaults to Serial
showLogLevelShow log level in log message, defaults to true
showModuleNameShow module name in log message, defaults to true
showTimestampShow timestamp in log message, defaults to true

Member Function Documentation

◆ debug()

template<class T , typename... Args>
void JBLogger::debug ( message,
Args...  args 
)
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.

Template Parameters
TThe type of the message parameter.
ArgsThe types of additional variadic arguments.
Parameters
messageThe error message, which can be of any type 'T'.
argsAdditional arguments to be formatted alongside the message.
Note
You can pass a message of any type 'T' supported by overloads of the log() function.

◆ error()

template<class T , typename... Args>
void JBLogger::error ( message,
Args...  args 
)
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.

Template Parameters
TThe type of the message parameter.
ArgsThe types of additional variadic arguments.
Parameters
messageThe error message, which can be of any type 'T'.
argsAdditional arguments to be formatted alongside the message.
Note
You can pass a message of any type 'T' supported by overloads of the log() function.

◆ getLogLevel()

LogLevel JBLogger::getLogLevel ( )

Returns the minimum log level for messages to be logged.

Returns
The minimum log level for messages to be logged.

◆ getOutput()

Stream & JBLogger::getOutput ( )

Returns the output stream for logging.

Returns
A reference to the output stream where log messages will be written.

◆ getShowLogLevel()

bool JBLogger::getShowLogLevel ( ) const

Returns whether the log level should be displayed in log messages.

Returns
A boolean value indicating whether the log level should be displayed in log messages.

◆ getShowModuleName()

bool JBLogger::getShowModuleName ( ) const

Returns whether the module name should be displayed in log messages.

Returns
A boolean value indicating whether the module name should be displayed in log messages.

◆ getShowTimestamp()

bool JBLogger::getShowTimestamp ( ) const

Returns whether timestamps should be displayed in log messages.

Returns
A boolean value indicating whether timestamps should be displayed in log messages.

◆ info()

template<class T , typename... Args>
void JBLogger::info ( message,
Args...  args 
)
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.

Template Parameters
TThe type of the message parameter.
ArgsThe types of additional variadic arguments.
Parameters
messageThe error message, which can be of any type 'T'.
argsAdditional arguments to be formatted alongside the message.
Note
You can pass a message of any type 'T' supported by overloads of the log() function.

◆ log() [1/2]

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.

Note
Uses sprintf to format the message, so string arguments needs to be given as char*
Parameters
logLevelThe log level to use for the message.
writePrefixIndicates whether to write the prefix before each message.
writeLinefeedSpecifies whether to write a line feed after the message.
messageThe format string for the message, with optional format specifiers.
...Variadic arguments to be formatted according to the format string.

◆ log() [2/2]

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.

Note
Uses sprintf to format the message, so string arguments needs to be given as char*
Parameters
logLevelThe log level to use for the message.
writePrefixIndicates whether to write the prefix before each message.
writeLinefeedSpecifies whether to write a line feed after the message.
messageThe format string for the message, with optional format specifiers.
...Variadic arguments to be formatted according to the format string.

◆ setLogLevel()

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.

Parameters
levelThe minimum log level to be logged.

◆ setOutput()

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.

Parameters
streamA reference to the output stream where log messages will be written.

◆ setShowLogLevel()

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.

Parameters
valueA boolean value indicating whether to show the log level in log messages.

◆ setShowModuleName()

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.

Parameters
valueA boolean value indicating whether to show the module name in log messages.

◆ setShowTimestamp()

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.

Parameters
valueA boolean value indicating whether to show timestamps in log messages.

◆ trace()

template<class T , typename... Args>
void JBLogger::trace ( message,
Args...  args 
)
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.

Template Parameters
TThe type of the message parameter.
ArgsThe types of additional variadic arguments.
Parameters
messageThe error message, which can be of any type 'T'.
argsAdditional arguments to be formatted alongside the message.
Note
You can pass a message of any type 'T' supported by overloads of the log() function.

◆ traceAsciiDump()

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.

Parameters
bufferA pointer to the memory buffer to be dumped.
sizeThe size (in bytes) of the memory buffer.

◆ traceBinaryDump()

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.

Parameters
bufferA pointer to the memory buffer to be dumped.
sizeThe size (in bytes) of the memory buffer.

◆ traceDump()

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.

Parameters
bufferA pointer to the memory buffer to be dumped.
sizeThe size (in bytes) of the memory buffer.

◆ traceHexDump()

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.

Parameters
bufferA pointer to the memory buffer to be dumped.
sizeThe size (in bytes) of the memory buffer.

◆ warning()

template<class T , typename... Args>
void JBLogger::warning ( message,
Args...  args 
)
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.

Template Parameters
TThe type of the message parameter.
ArgsThe types of additional variadic arguments.
Parameters
messageThe error message, which can be of any type 'T'.
argsAdditional arguments to be formatted alongside the message.
Note
You can pass a message of any type 'T' supported by overloads of the log() function.

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