diff --git a/src/cmd.c b/src/cmd.c index 0b7499c..21a9072 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -72,10 +72,10 @@ void init_cmd(void) { append_arg(supported_args, renderArg(i)); break; default: - LOG_ERROR("Undefined argument iterator %d", i); + LOG_ERROR_EXIT("Undefined argument iterator %d", i); } } - LOG_DEBUG("Cmd module initialised.") + LOG_DEBUG("Cmd module initialised."); } void exit_cmd(void) { @@ -119,7 +119,7 @@ void free_arg_list(struct ArgList* list) { struct CommandLineArg* parse_args(const int argc, char* argv[]) { if (argc < 2) { - LOG_ERROR_USER("At least 1 argument required."); + LOG_ERROR("At least 1 argument required."); usage(); exit(1); } diff --git a/src/tools/alloc_wrappers.h b/src/tools/alloc_wrappers.h index 8c27fe3..dbab595 100644 --- a/src/tools/alloc_wrappers.h +++ b/src/tools/alloc_wrappers.h @@ -6,7 +6,7 @@ #include #define FAILED_ALLOC_MESSAGE \ - LOG_ERROR("Allocation failed. Returned pointer is NULL."); + LOG_ERROR_EXIT("Allocation failed. Returned pointer is NULL."); #define cdo_malloc(size) ((void*)({ \ void *__ptr__ = malloc(size); \ diff --git a/src/tools/log.h b/src/tools/log.h index 3d36c3d..c2c70b4 100644 --- a/src/tools/log.h +++ b/src/tools/log.h @@ -90,21 +90,43 @@ static void create_log_line_simple(const char * _status, (cdo_log_enable_color) ? coloredLogLevels[SEVERITY] : plainLogLevels[SEVERITY] \ ) -#define LOG_INFO( fmt, ...) \ - create_log_line(GET_LOG_SEVERITY_STR(LEVEL_INFO), __FILE__, __func__, __LINE__, fmt, ##__VA_ARGS__); +#define LOG_INFO(fmt, ...) do { \ + if (cdo_log_enable_debug) { \ + create_log_line(GET_LOG_SEVERITY_STR(LEVEL_INFO), __FILE__, __func__, __LINE__, fmt, ##__VA_ARGS__); \ + } else { \ + create_log_line_simple(GET_LOG_SEVERITY_STR(LEVEL_INFO), fmt, ##__VA_ARGS__); \ + } \ +} while (0) -#define LOG_WARNING(fmt, ...) \ - create_log_line(GET_LOG_SEVERITY_STR(LEVEL_WARNING), __FILE__, __func__, __LINE__, fmt, ##__VA_ARGS__); +#define LOG_WARNING(fmt, ...) do { \ + if (cdo_log_enable_debug) { \ + create_log_line(GET_LOG_SEVERITY_STR(LEVEL_WARNING), __FILE__, __func__, __LINE__, fmt, ##__VA_ARGS__); \ + } else { \ + create_log_line_simple(GET_LOG_SEVERITY_STR(LEVEL_WARNING), fmt, ##__VA_ARGS__); \ + } \ +} while (0) -#define LOG_ERROR(fmt, ...) \ - create_log_line(GET_LOG_SEVERITY_STR(LEVEL_ERROR), __FILE__, __func__, __LINE__, fmt, ##__VA_ARGS__); \ - exit(1); +#define LOG_ERROR(fmt, ...) do { \ + if (cdo_log_enable_debug) { \ + create_log_line(GET_LOG_SEVERITY_STR(LEVEL_ERROR), __FILE__, __func__, __LINE__, fmt, ##__VA_ARGS__); \ + } else { \ + create_log_line_simple(GET_LOG_SEVERITY_STR(LEVEL_ERROR), fmt, ##__VA_ARGS__); \ + } \ +} while (0) -#define LOG_ERROR_USER(fmt, ...) \ - create_log_line_simple(GET_LOG_SEVERITY_STR(LEVEL_ERROR), fmt, ##__VA_ARGS__); +#define LOG_ERROR_EXIT(fmt, ...) do { \ + LOG_ERROR(fmt, ##__VA_ARGS__); \ + exit(1); \ +} while (0) + +#define LOG_DEBUG(fmt, ...) do { \ + if (cdo_log_enable_debug) { \ + create_log_line(GET_LOG_SEVERITY_STR(LEVEL_DEBUG), __FILE__, __func__, __LINE__, fmt, ##__VA_ARGS__); \ + } else { \ + create_log_line_simple(GET_LOG_SEVERITY_STR(LEVEL_DEBUG), fmt, ##__VA_ARGS__); \ + } \ +} while (0) -#define LOG_DEBUG(fmt, ...) \ - create_log_line(GET_LOG_SEVERITY_STR(LEVEL_DEBUG), __FILE__, __func__, __LINE__, fmt, ##__VA_ARGS__);