Allow disabling output/fine-tuning output

-nooutput disables output completely (both STDOUT and STDERR). -noinfo
disables INFO lines.  -nowarn disables WARN lines. -noerror disables
ERROR lines.
This commit is contained in:
Misa
2021-09-01 13:41:06 -07:00
committed by Misa Elizabeth Kai
parent c68a274c4f
commit 2eb9e23ecc
3 changed files with 63 additions and 0 deletions

View File

@@ -23,7 +23,11 @@
#define Color_BOLD_YELLOW COLOR("\x1b[1;33m")
#define Color_BOLD_RED COLOR("\x1b[1;31m")
static int output_enabled = 1;
static int color_enabled = 0;
static int info_enabled = 1;
static int warn_enabled = 1;
static int error_enabled = 1;
void vlog_init(void)
{
@@ -47,16 +51,41 @@ void vlog_init(void)
}
}
void vlog_toggle_output(const int enable_output)
{
output_enabled = enable_output;
}
void vlog_toggle_color(const int enable_color)
{
color_enabled = enable_color;
}
void vlog_toggle_info(const int enable_info)
{
info_enabled = enable_info;
}
void vlog_toggle_warn(const int enable_warn)
{
warn_enabled = enable_warn;
}
void vlog_toggle_error(const int enable_error)
{
error_enabled = enable_error;
}
int vlog_info(const char* text, ...)
{
va_list list;
int retval;
if (!output_enabled || !info_enabled)
{
return 0;
}
printf(Color_BOLD);
printf("[INFO]");
printf(Color_RESET);
@@ -76,6 +105,11 @@ int vlog_warn(const char* text, ...)
va_list list;
int retval;
if (!output_enabled || !warn_enabled)
{
return 0;
}
fprintf(stderr, Color_BOLD_YELLOW);
fprintf(stderr, "[WARN]");
fprintf(stderr, Color_RESET);
@@ -95,6 +129,11 @@ int vlog_error(const char* text, ...)
va_list list;
int retval;
if (!output_enabled || !error_enabled)
{
return 0;
}
fprintf(stderr, Color_BOLD_RED);
fprintf(stderr, "[ERROR]");
fprintf(stderr, Color_RESET);