log: add verbosity option

This commit is contained in:
tylen 2024-09-25 09:42:02 +00:00 committed by Vasily Davydov
parent 79ada91006
commit 5211e5800e
3 changed files with 21 additions and 10 deletions

View File

@ -9,7 +9,7 @@
static struct ArgList* supported_args; static struct ArgList* supported_args;
static const char* PREDEFINED_ARG_NAMES [] = { static const char* PREDEFINED_ARG_NAMES [] = {
"PROJECT", "project",
"help" "help"
}; };
@ -25,7 +25,7 @@ static const char* PREDEFINED_ARG_VALUES [] = {
void usage(void) { void usage(void) {
Buffer * usage_lines = buffer_create(DEFAULT_USAGE_LINE_LEN); Buffer * usage_lines = buffer_create(DEFAULT_USAGE_LINE_LEN);
buffer_append(usage_lines, "Usage: cdo [PROJECT] [OPTION]\n"); buffer_append(usage_lines, "Usage: cdo [OPTION]...\n");
buffer_append(usage_lines, "Parse TODO's of the PROJECT.\n\n"); buffer_append(usage_lines, "Parse TODO's of the PROJECT.\n\n");
for (int i = 0; i < ARG_COUNT; i++) { for (int i = 0; i < ARG_COUNT; i++) {
buffer_append(usage_lines, supported_args->args[i].name); buffer_append(usage_lines, supported_args->args[i].name);

View File

@ -2,10 +2,12 @@
char* cdo_log_enable_color = NULL; char* cdo_log_enable_color = NULL;
char* cdo_log_enable_debug = NULL; char* cdo_log_enable_debug = NULL;
char* cdo_log_enable_verbose = NULL;
void init_log(void) { void init_log(void) {
cdo_log_enable_color = getenv(LOG_COLORED_OUTPUT_ENV); cdo_log_enable_color = getenv(LOG_COLORED_OUTPUT_ENV);
cdo_log_enable_debug = getenv(LOG_DEBUG_MESSAGES_ENV); cdo_log_enable_debug = getenv(LOG_DEBUG_MESSAGES_ENV);
cdo_log_enable_verbose = getenv(LOG_VERBOSITY_ENV);
LOG_DEBUG("Log module initialised."); LOG_DEBUG("Log module initialised.");
if (!cdo_log_enable_color) { if (!cdo_log_enable_color) {
LOG_DEBUG("%s env not defined.", LOG_COLORED_OUTPUT_ENV); LOG_DEBUG("%s env not defined.", LOG_COLORED_OUTPUT_ENV);
@ -13,4 +15,7 @@ void init_log(void) {
if (!cdo_log_enable_debug) { if (!cdo_log_enable_debug) {
LOG_DEBUG("%s env not defined", LOG_DEBUG_MESSAGES_ENV); LOG_DEBUG("%s env not defined", LOG_DEBUG_MESSAGES_ENV);
} }
if (!cdo_log_enable_verbose) {
LOG_DEBUG("%s env not defined", LOG_VERBOSITY_ENV);
}
} }

View File

@ -7,6 +7,7 @@
#define LOG_COLORED_OUTPUT_ENV "CDO_LOG_ENABLE_COLOR" #define LOG_COLORED_OUTPUT_ENV "CDO_LOG_ENABLE_COLOR"
#define LOG_DEBUG_MESSAGES_ENV "CDO_LOG_ENABLE_DEBUG" #define LOG_DEBUG_MESSAGES_ENV "CDO_LOG_ENABLE_DEBUG"
#define LOG_VERBOSITY_ENV "CDO_LOG_ENABLE_VERBOSE"
#include <assert.h> #include <assert.h>
#define INT_ASSERT(statement) assert(statement) #define INT_ASSERT(statement) assert(statement)
@ -35,6 +36,7 @@ static const char* plainLogLevels[] = {
extern char* cdo_log_enable_color; extern char* cdo_log_enable_color;
extern char* cdo_log_enable_debug; extern char* cdo_log_enable_debug;
extern char* cdo_log_enable_verbose;
extern void init_log(void); extern void init_log(void);
#define LOG_BUFFER_MAX_CAP 256 #define LOG_BUFFER_MAX_CAP 256
@ -91,7 +93,7 @@ static void create_log_line_simple(const char * _status,
) )
#define LOG_INFO(fmt, ...) do { \ #define LOG_INFO(fmt, ...) do { \
if (cdo_log_enable_debug) { \ if (cdo_log_enable_verbose) { \
create_log_line(GET_LOG_SEVERITY_STR(LEVEL_INFO), __FILE__, __func__, __LINE__, fmt, ##__VA_ARGS__); \ create_log_line(GET_LOG_SEVERITY_STR(LEVEL_INFO), __FILE__, __func__, __LINE__, fmt, ##__VA_ARGS__); \
} else { \ } else { \
create_log_line_simple(GET_LOG_SEVERITY_STR(LEVEL_INFO), fmt, ##__VA_ARGS__); \ create_log_line_simple(GET_LOG_SEVERITY_STR(LEVEL_INFO), fmt, ##__VA_ARGS__); \
@ -100,14 +102,16 @@ static void create_log_line_simple(const char * _status,
#define LOG_WARNING(fmt, ...) do { \ #define LOG_WARNING(fmt, ...) do { \
if (cdo_log_enable_debug) { \ if (cdo_log_enable_debug) { \
create_log_line(GET_LOG_SEVERITY_STR(LEVEL_WARNING), __FILE__, __func__, __LINE__, fmt, ##__VA_ARGS__); \ if (cdo_log_enable_verbose) { \
} else { \ create_log_line(GET_LOG_SEVERITY_STR(LEVEL_WARNING), __FILE__, __func__, __LINE__, fmt, ##__VA_ARGS__); \
create_log_line_simple(GET_LOG_SEVERITY_STR(LEVEL_WARNING), fmt, ##__VA_ARGS__); \ } else { \
create_log_line_simple(GET_LOG_SEVERITY_STR(LEVEL_WARNING), fmt, ##__VA_ARGS__); \
} \
} \ } \
} while (0) } while (0)
#define LOG_ERROR(fmt, ...) do { \ #define LOG_ERROR(fmt, ...) do { \
if (cdo_log_enable_debug) { \ if (cdo_log_enable_verbose) { \
create_log_line(GET_LOG_SEVERITY_STR(LEVEL_ERROR), __FILE__, __func__, __LINE__, fmt, ##__VA_ARGS__); \ create_log_line(GET_LOG_SEVERITY_STR(LEVEL_ERROR), __FILE__, __func__, __LINE__, fmt, ##__VA_ARGS__); \
} else { \ } else { \
create_log_line_simple(GET_LOG_SEVERITY_STR(LEVEL_ERROR), fmt, ##__VA_ARGS__); \ create_log_line_simple(GET_LOG_SEVERITY_STR(LEVEL_ERROR), fmt, ##__VA_ARGS__); \
@ -121,9 +125,11 @@ static void create_log_line_simple(const char * _status,
#define LOG_DEBUG(fmt, ...) do { \ #define LOG_DEBUG(fmt, ...) do { \
if (cdo_log_enable_debug) { \ if (cdo_log_enable_debug) { \
create_log_line(GET_LOG_SEVERITY_STR(LEVEL_DEBUG), __FILE__, __func__, __LINE__, fmt, ##__VA_ARGS__); \ if (cdo_log_enable_verbose) { \
} else { \ create_log_line(GET_LOG_SEVERITY_STR(LEVEL_DEBUG), __FILE__, __func__, __LINE__, fmt, ##__VA_ARGS__); \
create_log_line_simple(GET_LOG_SEVERITY_STR(LEVEL_DEBUG), fmt, ##__VA_ARGS__); \ } else { \
create_log_line_simple(GET_LOG_SEVERITY_STR(LEVEL_DEBUG), fmt, ##__VA_ARGS__); \
} \
} \ } \
} while (0) } while (0)