log: add verbosity option
This commit is contained in:
parent
79ada91006
commit
5211e5800e
@ -9,7 +9,7 @@
|
||||
static struct ArgList* supported_args;
|
||||
|
||||
static const char* PREDEFINED_ARG_NAMES [] = {
|
||||
"PROJECT",
|
||||
"project",
|
||||
"help"
|
||||
};
|
||||
|
||||
@ -25,7 +25,7 @@ static const char* PREDEFINED_ARG_VALUES [] = {
|
||||
|
||||
void usage(void) {
|
||||
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");
|
||||
for (int i = 0; i < ARG_COUNT; i++) {
|
||||
buffer_append(usage_lines, supported_args->args[i].name);
|
||||
|
||||
@ -2,10 +2,12 @@
|
||||
|
||||
char* cdo_log_enable_color = NULL;
|
||||
char* cdo_log_enable_debug = NULL;
|
||||
char* cdo_log_enable_verbose = NULL;
|
||||
|
||||
void init_log(void) {
|
||||
cdo_log_enable_color = getenv(LOG_COLORED_OUTPUT_ENV);
|
||||
cdo_log_enable_debug = getenv(LOG_DEBUG_MESSAGES_ENV);
|
||||
cdo_log_enable_verbose = getenv(LOG_VERBOSITY_ENV);
|
||||
LOG_DEBUG("Log module initialised.");
|
||||
if (!cdo_log_enable_color) {
|
||||
LOG_DEBUG("%s env not defined.", LOG_COLORED_OUTPUT_ENV);
|
||||
@ -13,4 +15,7 @@ void init_log(void) {
|
||||
if (!cdo_log_enable_debug) {
|
||||
LOG_DEBUG("%s env not defined", LOG_DEBUG_MESSAGES_ENV);
|
||||
}
|
||||
if (!cdo_log_enable_verbose) {
|
||||
LOG_DEBUG("%s env not defined", LOG_VERBOSITY_ENV);
|
||||
}
|
||||
}
|
||||
@ -7,6 +7,7 @@
|
||||
|
||||
#define LOG_COLORED_OUTPUT_ENV "CDO_LOG_ENABLE_COLOR"
|
||||
#define LOG_DEBUG_MESSAGES_ENV "CDO_LOG_ENABLE_DEBUG"
|
||||
#define LOG_VERBOSITY_ENV "CDO_LOG_ENABLE_VERBOSE"
|
||||
|
||||
#include <assert.h>
|
||||
#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_debug;
|
||||
extern char* cdo_log_enable_verbose;
|
||||
extern void init_log(void);
|
||||
|
||||
#define LOG_BUFFER_MAX_CAP 256
|
||||
@ -91,7 +93,7 @@ static void create_log_line_simple(const char * _status,
|
||||
)
|
||||
|
||||
#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__); \
|
||||
} else { \
|
||||
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 { \
|
||||
if (cdo_log_enable_debug) { \
|
||||
if (cdo_log_enable_verbose) { \
|
||||
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, ...) 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__); \
|
||||
} else { \
|
||||
create_log_line_simple(GET_LOG_SEVERITY_STR(LEVEL_ERROR), fmt, ##__VA_ARGS__); \
|
||||
@ -121,10 +125,12 @@ static void create_log_line_simple(const char * _status,
|
||||
|
||||
#define LOG_DEBUG(fmt, ...) do { \
|
||||
if (cdo_log_enable_debug) { \
|
||||
if (cdo_log_enable_verbose) { \
|
||||
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)
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user