1
0
Fork 0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-12-22 17:49:43 +01:00

Add debug logs

These are disabled by default, because they're noisy. To enable them,
pass -debug.
This commit is contained in:
Misa 2021-09-01 14:11:23 -07:00 committed by Misa Elizabeth Kai
parent 2eb9e23ecc
commit b652d327dc
3 changed files with 39 additions and 0 deletions

View file

@ -22,9 +22,11 @@
#define Color_BOLD COLOR("\x1b[1m")
#define Color_BOLD_YELLOW COLOR("\x1b[1;33m")
#define Color_BOLD_RED COLOR("\x1b[1;31m")
#define Color_BOLD_GRAY COLOR("\x1b[1;90m")
static int output_enabled = 1;
static int color_enabled = 0;
static int debug_enabled = 0;
static int info_enabled = 1;
static int warn_enabled = 1;
static int error_enabled = 1;
@ -61,6 +63,11 @@ void vlog_toggle_color(const int enable_color)
color_enabled = enable_color;
}
void vlog_toggle_debug(const int enable_debug)
{
debug_enabled = enable_debug;
}
void vlog_toggle_info(const int enable_info)
{
info_enabled = enable_info;
@ -76,6 +83,30 @@ void vlog_toggle_error(const int enable_error)
error_enabled = enable_error;
}
int vlog_debug(const char* text, ...)
{
va_list list;
int retval;
if (!output_enabled || !debug_enabled)
{
return 0;
}
printf(Color_BOLD_GRAY);
printf("[DEBUG]");
printf(Color_RESET);
printf(" ");
va_start(list, text);
retval = vprintf(text, list);
va_end(list);
putchar('\n');
return retval;
}
int vlog_info(const char* text, ...)
{
va_list list;

View file

@ -12,12 +12,16 @@ void vlog_toggle_output(int enable_output);
void vlog_toggle_color(int enable_color);
void vlog_toggle_debug(int enable_debug);
void vlog_toggle_info(int enable_info);
void vlog_toggle_warn(int enable_warn);
void vlog_toggle_error(int enable_error);
int vlog_debug(const char* text, ...);
int vlog_info(const char* text, ...);
int vlog_warn(const char* text, ...);

View file

@ -444,6 +444,10 @@ int main(int argc, char *argv[])
{
vlog_toggle_color(0);
}
else if (ARG("-debug"))
{
vlog_toggle_debug(1);
}
else if (ARG("-noinfo"))
{
vlog_toggle_info(0);