Logger Module¶
Note
Features¶
Specifying the destination¶
Varous other modules declare a Log Stream function that can be used to output text.
Currently available are:
-
void LCD_Stream(const char *string, bool new_line)¶
LCD Stream function for use with the logger.
- Parameters
string – String to print
new_line – Advance a line after printing
-
void SERIAL_Stream(const char *string, bool new_line)¶
Serial Stream function for use with the logger.
- Parameters
string – String to print
new_line – Advance a line after printing
To select a stream, the LOG_SetDestination
function is used.
LOG_SetDestination(LCD_Stream);
LOG_Info("Logging to Display");
LOG_SetDestination(SERIAL_Stream);
LOG_Info("Logging to UART");
-
void LOG_SetDestination(LOG_Stream_t stream)¶
Sets the new destination where log output should go to.
- Parameters
stream – Stream function of destination
-
LOG_Stream_t LOG_GetDestination(void)¶
Gets the currently set logging destination.
- Returns
Logging stream
Logging functions¶
There are multiple different logging functions that for the most part only differ in the prefix that is added in front of the message.
Important
All these functions work exactly like printf
. The first parameter is a printf format string and the following parameters are the values
used to replace the placeholders in the format string.
For more information, check the printf
function documentation here: cppreference.com
The following example prints values that have been previously read from various environmental sensors in a formatted manner.
LOG_SetDestination(LCD_Stream);
LOG_Info("Environment Parameters: %.2f°C, %.1f%%R, %01fhPa, [ %d, %d, %d ]",
temperature,
humidity,
pressure,
acceleration_x,
acceleration_y,
acceleration_z
);
// Prints "[INFO] Environment Parameters: 23.24°C, 42.2%R, 1050.1hPa, [ 142, 243, 423 ]" to the LCD
-
void LOG_Debug(const char *fmt, ...)¶
Prints a debug string to the current stream.
Note
Only prints in debug mode
- Parameters
fmt – printf format string
... – Format arguments
-
void LOG_Info(const char *fmt, ...)¶
Prints a info string to the current stream.
- Parameters
fmt – printf format string
... – Format arguments
-
void LOG_Warn(const char *fmt, ...)¶
Prints a warning string to the current stream.
- Parameters
fmt – printf format string
... – Format arguments
-
void LOG_Error(const char *fmt, ...)¶
Prints a error string to the current stream.
- Parameters
fmt – printf format string
... – Format arguments
-
void LOG_Fatal(const char *fmt, ...)¶
Prints a fatal error string to the current stream.
- Parameters
fmt – printf format string
... – Format arguments