From 2eb9e23ecc28cb8eca16380602d774ce63b68cf3 Mon Sep 17 00:00:00 2001 From: Misa Date: Wed, 1 Sep 2021 13:41:06 -0700 Subject: [PATCH] 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. --- desktop_version/src/Vlogging.c | 39 ++++++++++++++++++++++++++++++++++ desktop_version/src/Vlogging.h | 8 +++++++ desktop_version/src/main.cpp | 16 ++++++++++++++ 3 files changed, 63 insertions(+) diff --git a/desktop_version/src/Vlogging.c b/desktop_version/src/Vlogging.c index e50f5696..c1da95f3 100644 --- a/desktop_version/src/Vlogging.c +++ b/desktop_version/src/Vlogging.c @@ -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); diff --git a/desktop_version/src/Vlogging.h b/desktop_version/src/Vlogging.h index 22802f3b..90ff9089 100644 --- a/desktop_version/src/Vlogging.h +++ b/desktop_version/src/Vlogging.h @@ -8,8 +8,16 @@ extern "C" void vlog_init(void); +void vlog_toggle_output(int enable_output); + void vlog_toggle_color(int enable_color); +void vlog_toggle_info(int enable_info); + +void vlog_toggle_warn(int enable_warn); + +void vlog_toggle_error(int enable_error); + int vlog_info(const char* text, ...); int vlog_warn(const char* text, ...); diff --git a/desktop_version/src/main.cpp b/desktop_version/src/main.cpp index 24eb58d8..2e9ba47d 100644 --- a/desktop_version/src/main.cpp +++ b/desktop_version/src/main.cpp @@ -432,6 +432,10 @@ int main(int argc, char *argv[]) playassets = "levels/" + std::string(argv[i]) + ".vvvvvv"; }) } + else if (ARG("-nooutput")) + { + vlog_toggle_output(0); + } else if (ARG("-forcecolor") || ARG("-forcecolour")) { vlog_toggle_color(1); @@ -440,6 +444,18 @@ int main(int argc, char *argv[]) { vlog_toggle_color(0); } + else if (ARG("-noinfo")) + { + vlog_toggle_info(0); + } + else if (ARG("-nowarn")) + { + vlog_toggle_warn(0); + } + else if (ARG("-noerror")) + { + vlog_toggle_error(0); + } #undef ARG_INNER #undef ARG else