Change logger to use critical and fatal instead of error

This commit is contained in:
2023-11-01 13:56:56 +01:00
parent a0f5d27909
commit 0af40da311
2 changed files with 37 additions and 18 deletions

View File

@@ -39,7 +39,8 @@ To use the logging system, include `log.h` in your source file, and use the foll
LOG_DEBUG(TAG, fmt, ...)
LOG_INFO(TAG, fmt, ...)
LOG_WARN(TAG, fmt, ...)
LOG_ERROR(TAG, fmt, ...)
LOG_CRIT(TAG, fmt, ...)
LOG_FATAL(TAG, fmt, ...)
```
The same format specifiers as in `printf` can be used.
@@ -73,7 +74,13 @@ before you include `log.h`, you can define custom log levels by defining the fol
```c
// Only log messages with level ERROR will be printed
#define LOGGER_LEVEL_ERROR
#define LOGGER_LEVEL_CRITICAL
#include "log.h"
```
```c
// Only log messages with level ERROR will be printed
#define LOGGER_LEVEL_FATAL
#include "log.h"
```
@@ -84,7 +91,7 @@ Default is `0`
### Log Output Format
Each log entry is formatted to include the following information:
- Log level ([Debug], [Info], [Warn], [Error])
- Log level ([Debug], [Info], [Warn], [Critical], [Fatal])
- Timestamp (in milliseconds since boot)
- Tag
- The log message
@@ -106,7 +113,8 @@ int main(void) {
LOG_DEBUG(TAG, "This message will not be printed");
LOG_INFO(TAG, "This message will be printed");
LOG_WARN(TAG, "This message will be printed");
LOG_ERROR(TAG, "This message will be printed");
LOG_CRIT(TAG, "This message will be printed");
LOG_FATAL(TAG, "This message will be printed");
for (int i = 0; i < 3; i++) {
LOG_INFO(TAG, "Iteration %d of %d", i, 3);
@@ -117,10 +125,11 @@ int main(void) {
```
Result:
```
[Info] (2009) main: This message will be printed
[Warning] (2026) main: This message will be printed
[Error] (2033) main: This message will be printed
[Info] (2040) main: Iteration 0 of 3
[Info] (2047) main: Iteration 1 of 3
[Info] (2054) main: Iteration 2 of 3
[Info] (2009) main: This message will be printed
[Warning] (2026) main: This message will be printed
[CRITICAL] (2033) main: This message will be printed
[FATAL] (2040) main: This message will be printed
[Info] (2040) main: Iteration 0 of 3
[Info] (2047) main: Iteration 1 of 3
[Info] (2054) main: Iteration 2 of 3
```