fix: logging calls

This commit is contained in:
Tobias Reisinger 2020-04-14 01:51:40 +02:00
parent db64e4f820
commit 6ecef87f24
3 changed files with 23 additions and 14 deletions

View file

@ -8,6 +8,13 @@
#include <config.h> #include <config.h>
#include <macros.h> #include <macros.h>
#define COLOR_TRACE COLOR_GREEN
#define COLOR_DEBUG COLOR_BLUE
#define COLOR_INFO COLOR_CYAN
#define COLOR_WARN COLOR_YELLOW
#define COLOR_ERROR COLOR_RED
#define COLOR_FATAL COLOR_MAGENTA
#define _LOGGER_TIMESTAMP_SIZE 32 #define _LOGGER_TIMESTAMP_SIZE 32
char _LOGGER_TIMESTAMP[_LOGGER_TIMESTAMP_SIZE]; char _LOGGER_TIMESTAMP[_LOGGER_TIMESTAMP_SIZE];
@ -17,37 +24,37 @@ logger_get_timestamp();
#define _LOGGER_MESSAGE(msg) COLOR_NONE " %s %s:%d:%s: " msg "\n", logger_get_timestamp(), __FILENAME__, __LINE__, __func__ #define _LOGGER_MESSAGE(msg) COLOR_NONE " %s %s:%d:%s: " msg "\n", logger_get_timestamp(), __FILENAME__, __LINE__, __func__
#if LOG_LEVEL >= LOG_LEVEL_TRACE #if LOG_LEVEL >= LOG_LEVEL_TRACE
#define LOG_TRACE(msg, ...) fprintf(stdout, COLOR_GREEN "[TRACE]" _LOGGER_MESSAGE(msg), ##__VA_ARGS__) #define LOG_TRACE(msg, ...) fprintf(stdout, COLOR_TRACE "[TRACE]" _LOGGER_MESSAGE(msg), ##__VA_ARGS__)
#else #else
#define LOG_TRACE(msg, ...) #define LOG_TRACE(msg, ...)
#endif #endif
#if LOG_LEVEL >= LOG_LEVEL_DEBUG #if LOG_LEVEL >= LOG_LEVEL_DEBUG
#define LOG_DEBUG(msg, ...) fprintf(stdout, COLOR_BLUE "[DEBUG]" _LOGGER_MESSAGE(msg), ##__VA_ARGS__) #define LOG_DEBUG(msg, ...) fprintf(stdout, COLOR_DEBUG "[DEBUG]" _LOGGER_MESSAGE(msg), ##__VA_ARGS__)
#else #else
#define LOG_DEBUG(msg, ...) #define LOG_DEBUG(msg, ...)
#endif #endif
#if LOG_LEVEL >= LOG_LEVEL_INFO #if LOG_LEVEL >= LOG_LEVEL_INFO
#define LOG_INFO(msg, ...) fprintf(stdout, COLOR_CYAN "[ INFO]" _LOGGER_MESSAGE(msg), ##__VA_ARGS__) #define LOG_INFO(msg, ...) fprintf(stdout, COLOR_INFO "[ INFO]" _LOGGER_MESSAGE(msg), ##__VA_ARGS__)
#else #else
#define LOG_INFO(msg, ...) #define LOG_INFO(msg, ...)
#endif #endif
#if LOG_LEVEL >= LOG_LEVEL_WARN #if LOG_LEVEL >= LOG_LEVEL_WARN
#define LOG_WARN(msg, ...) fprintf(stdout, COLOR_YELLOW "[ WARN]" _LOGGER_MESSAGE(msg), ##__VA_ARGS__) #define LOG_WARN(msg, ...) fprintf(stdout, COLOR_WARN "[ WARN]" _LOGGER_MESSAGE(msg), ##__VA_ARGS__)
#else #else
#define LOG_WARN(msg, ...) #define LOG_WARN(msg, ...)
#endif #endif
#if LOG_LEVEL >= LOG_LEVEL_ERROR #if LOG_LEVEL >= LOG_LEVEL_ERROR
#define LOG_ERROR(msg, ...) fprintf(stderr, COLOR_RED "[ERROR]" _LOGGER_MESSAGE(msg), ##__VA_ARGS__) #define LOG_ERROR(msg, ...) fprintf(stderr, COLOR_ERROR "[ERROR]" _LOGGER_MESSAGE(msg), ##__VA_ARGS__)
#else #else
#define LOG_ERROR(msg, ...) #define LOG_ERROR(msg, ...)
#endif #endif
#if LOG_LEVEL >= LOG_LEVEL_FATAL #if LOG_LEVEL >= LOG_LEVEL_FATAL
#define LOG_FATAL(msg, ...) fprintf(stderr, COLOR_MAGENTA "[FATAL]" _LOGGER_MESSAGE(msg), ##__VA_ARGS__) #define LOG_FATAL(msg, ...) fprintf(stderr, COLOR_FATAL "[FATAL]" _LOGGER_MESSAGE(msg), ##__VA_ARGS__)
#else #else
#define LOG_FATAL(msg, ...) #define LOG_FATAL(msg, ...)
#endif #endif

View file

@ -3,13 +3,15 @@
#include <logger.h> #include <logger.h>
#ifdef WIRING_PI_DEBUG #define LOG_WIRING_DEBUG(x, ...) LOG_DEBUG(x, ##__VA_ARGS__)
#define wiringPiSetup() LOG_INFO("wiringPi wiringPiSetup()")
#define wiringPiSetupSys() LOG_INFO("wiringPi wiringPiSetupSys()")
#define pinMode(x,y) LOG_INFO("wiringPi pinMode(%d, %d)", x, y)
#define digitalWrite(x,y) LOG_INFO("wiringPi digitalWrite(%d, %d)", x, y)
#define piFaceSetup(x) LOG_INFO("wiringPi piFaceSetup(%d)", x) #ifdef WIRING_PI_DEBUG
#define wiringPiSetup() LOG_WIRING_DEBUG("wiringPi wiringPiSetup()")
#define wiringPiSetupSys() LOG_WIRING_DEBUG("wiringPi wiringPiSetupSys()")
#define pinMode(x,y) LOG_WIRING_DEBUG("wiringPi pinMode(%d, %d)", x, y)
#define digitalWrite(x,y) LOG_WIRING_DEBUG("wiringPi digitalWrite(%d, %d)", x, y)
#define piFaceSetup(x) LOG_WIRING_DEBUG("wiringPi piFaceSetup(%d)", x)
#endif #endif
#endif /* CONTROLLER_WIRING_DEBUG_H */ #endif /* CONTROLLER_WIRING_DEBUG_H */

4
main.c
View file

@ -130,13 +130,13 @@ main(int argc, char** argv)
/******************** START MAIN LOOP ********************/ /******************** START MAIN LOOP ********************/
while(1) for(;;)
{ {
ret = poll(fds, fd_count, timeout_msecs); ret = poll(fds, fd_count, timeout_msecs);
if(ret == 0) if(ret == 0)
{ {
LOG_TRACE("idle loop"); LOG_DEBUG("===== IDLE LOOP START =====");
for(uint_fast8_t i = 0; i < this_controller->relay_count; ++i) for(uint_fast8_t i = 0; i < this_controller->relay_count; ++i)
{ {
relay_t *relay = this_controller->relays[i]; relay_t *relay = this_controller->relays[i];