|
| #define | _FILE strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__ |
| |
| #define | NO_LOG 0x00 |
| |
| #define | ERROR_LEVEL 0x01 |
| |
| #define | INFO_LEVEL 0x02 |
| |
| #define | DEBUG_LEVEL 0x03 |
| |
| #define | LOG_LEVEL DEBUG_LEVEL |
| |
| #define | PRINTFUNCTION(format, ...) fprintf(MAIN_LOG_FILE, format, __VA_ARGS__); fflush(MAIN_LOG_FILE) |
| |
| #define | LOG_FMT "%s | %-7s | %-15s | %s:%d | " |
| |
| #define | LOG_ARGS(LOG_TAG) timenow(), LOG_TAG, _FILE, __FUNCTION__, __LINE__ |
| |
| #define | NEWLINE "\n" |
| |
| #define | ERROR_TAG "ERROR" |
| |
| #define | INFO_TAG "INFO" |
| |
| #define | DEBUG_TAG "DEBUG" |
| |
| #define | LOG_DEBUG(message, args...) PRINTFUNCTION(LOG_FMT message NEWLINE, LOG_ARGS(DEBUG_TAG), ## args) |
| |
| #define | LOG_INFO(message, args...) PRINTFUNCTION(LOG_FMT message NEWLINE, LOG_ARGS(INFO_TAG), ## args) |
| |
| #define | LOG_ERROR(message, args...) PRINTFUNCTION(LOG_FMT message NEWLINE, LOG_ARGS(ERROR_TAG), ## args) |
| |
| #define | LOG_IF_ERROR(condition, message, args...) if (condition) PRINTFUNCTION(LOG_FMT message NEWLINE, LOG_ARGS(ERROR_TAG), ## args) |
| |
The file contains the logging macros
Each of the macros behave like printf()
Sample usage:
LOG_DEBUG(
"Maybe i can touch this button...");
int going_down = 1;
LOG_IF_ERROR(going_down,
"i'm going down... if only i had used macro-logger...");
Definition in file log.h.