diff --git a/CMakeLists.txt b/CMakeLists.txt index 7114332..af2fced 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,8 @@ project(controller) add_executable(controller main.c) -option(WIRING_PI_DEBUG "Use WiringPi Debugging Tool" OFF) +option(WIRING_PI_DEBUG "Use WiringPi Debugging Tool (0=off, 1=silent, 2=LOG_DEBUG) (0)" OFF) +option(LOG_LEVEL "Set logging level (5=trace, 4=debug, 3=info, 2=warn, 1=error, 0=fatal) (3)" OFF) SET(CMAKE_C_FLAGS "-Wall -Wextra -lwiringPi -lwiringPiDev -luuid -llmdb -g") @@ -11,9 +12,18 @@ string(LENGTH "${CMAKE_SOURCE_DIR}/" SOURCE_PATH_SIZE) add_definitions("-DSOURCE_PATH_SIZE=${SOURCE_PATH_SIZE}") if(WIRING_PI_DEBUG) - message("Using wiringPi debug calls") - add_compile_definitions("WIRING_PI_DEBUG") + if(WIRING_PI_DEBUG GREATER 1) + message("Showing wiringPi calls as debug") + else(WIRING_PI_DEBUG GREATER 1) + message("Ignoring wiringPi calls") + endif(WIRING_PI_DEBUG GREATER 1) + add_definitions("-DWIRING_PI_DEBUG=${WIRING_PI_DEBUG}") endif(WIRING_PI_DEBUG) +if(LOG_LEVEL) + add_definitions("-DLOG_LEVEL=${LOG_LEVEL}") +else(LOG_LEVEL) + add_definitions("-DLOG_LEVEL=3") +endif(LOG_LEVEL) aux_source_directory(vendor VENDOR_SRC) # vendor first to put their warnings on top aux_source_directory(. SRC_DIR) diff --git a/handlers/discovery.c b/handlers/discovery.c index 03decfa..698ee2c 100644 --- a/handlers/discovery.c +++ b/handlers/discovery.c @@ -29,7 +29,7 @@ handler_discovery(int fd, controller_t *controller) LOG_ERROR("received invalid discovery from %s", inet_ntoa(si_other.sin_addr)); return; } - LOG_DEBUG("received discovery from %s for port %d", inet_ntoa(si_other.sin_addr), discovery_answer_port); + LOG_INFO("received discovery from %s:%d", inet_ntoa(si_other.sin_addr), discovery_answer_port); if(discovery_answer_port == 0) { diff --git a/include/constants.h b/include/constants.h index a9bb525..a350491 100644 --- a/include/constants.h +++ b/include/constants.h @@ -23,13 +23,6 @@ */ #define MDB_MAXDBS 8 -/** - * @brief Indicates to which level to log - * - * @see include/log_levels.h - */ -#define LOG_LEVEL LOG_LEVEL_DEBUG - /** * @brief How many milli seconds to wait until poll timeout in main loop */ @@ -37,4 +30,8 @@ #define PIFACE_GPIO_BASE 200 +#ifndef LOG_LEVEL + #define LOG_LEVEL LOG_LEVEL_INFO +#endif + #endif /* CONTROLLER_CONTANTS_H */ diff --git a/include/wiring_debug.h b/include/wiring_debug.h index 664d88b..906f6cd 100644 --- a/include/wiring_debug.h +++ b/include/wiring_debug.h @@ -3,9 +3,13 @@ #include -#define LOG_WIRING_DEBUG(x, ...) LOG_DEBUG(x, ##__VA_ARGS__) - #ifdef WIRING_PI_DEBUG + #if WIRING_PI_DEBUG > 1 + #define LOG_WIRING_DEBUG(x, ...) LOG_DEBUG(x, ##__VA_ARGS__) + #else + #define LOG_WIRING_DEBUG(x, ...) + #endif + #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)