Browse Source

debug: remove console_level/file_level — simplified output routing

Remove secondary level filtering in debug_output(). Now the only filter
is debug_should_output() (per-category + global fallback). Output goes
to file (if file_output set) or console (if console_enabled), with no
additional level check.

Removed:
- debug_set_console_level(), debug_set_file_level()
- console_level, file_level fields from debug_config_t
- debug_set_level() no longer sets console_level
chatgui
Evgeny 3 months ago
parent
commit
637b21da9e
  1. 24
      lib/debug_config.c
  2. 8
      lib/debug_config.h
  3. 2
      tests/test_lwip_tcp.c
  4. 4
      tools/chatgui/transport/utun_node.cpp

24
lib/debug_config.c

@ -223,8 +223,6 @@ void debug_config_init(void) {
// Dual output defaults
g_debug_config.file_output = NULL; // No file by default
g_debug_config.file_level = DEBUG_LEVEL_TRACE; // File gets everything
g_debug_config.console_level = DEBUG_LEVEL_INFO; // Console gets INFO+
g_debug_config.console_enabled = 1; // Console enabled
g_debug_config.thread_marker = 0; // No thread marker by default
}
@ -232,7 +230,6 @@ void debug_config_init(void) {
/* Set debug level */
void debug_set_level(debug_level_t level) {
g_debug_config.level = level;
g_debug_config.console_level = level;
}
/* Set debug level for specific category (0 = disabled, otherwise uses that level) */
@ -284,16 +281,6 @@ void debug_set_output_file(const char* file_path) {
}
/* Set console log level */
void debug_set_console_level(debug_level_t level) {
g_debug_config.console_level = level;
}
/* Set file log level */
void debug_set_file_level(debug_level_t level) {
g_debug_config.file_level = level;
}
/* Enable/disable console output */
void debug_enable_console(int enable) {
g_debug_config.console_enabled = enable;
}
@ -446,15 +433,12 @@ void debug_output(debug_level_t level, debug_category_t category_idx,
va_end(args);
/* Output to console if enabled and level is sufficient */
if (g_debug_config.console_enabled && level <= g_debug_config.console_level) {
fprintf(stdout, "%s", buffer);
fflush(stdout);
}
/* Output to file if open and level is sufficient */
if (g_debug_config.file_output && level <= g_debug_config.file_level) {
if (g_debug_config.file_output) {
fprintf(g_debug_config.file_output, "%s", buffer);
fflush(g_debug_config.file_output);
} else if (g_debug_config.console_enabled) {
fprintf(stdout, "%s", buffer);
fflush(stdout);
}
#undef BUFFER_SIZE
}

8
lib/debug_config.h

@ -78,8 +78,6 @@ typedef struct {
// Dual output support
FILE* file_output; // File handle for log file (NULL if not open)
debug_level_t file_level; // Log level for file output
debug_level_t console_level; // Log level for console output
int console_enabled; // Enable console output
int thread_marker; // Thread identification (0=none, e.g. 2 for uasync)
} debug_config_t;
@ -111,10 +109,8 @@ void debug_enable_function_name(int enable);
void debug_enable_file_line(int enable);
void debug_set_output_file(const char* file_path);
/* Dual output configuration */
void debug_set_console_level(debug_level_t level);
void debug_set_file_level(debug_level_t level);
void debug_enable_file_output(const char* file_path, int truncate);
/* Dual output configuration */
void debug_enable_file_output(const char* file_path, int truncate);
void debug_disable_file_output(void);
int debug_reopen_log(void);
void debug_enable_console(int enable);

2
tests/test_lwip_tcp.c

@ -629,7 +629,7 @@ int main(int argc, char *argv[])
srand(seed);
printf("seed=%u\n", seed);
debug_config_init();
debug_set_console_level(DEBUG_LEVEL_NONE);
g_debug_config.console_enabled = 0;
debug_set_category_level(DEBUG_CATEGORY_ALL, DEBUG_LEVEL_ERROR);
#ifndef _WIN32
setlinebuf(stdout);

4
tools/chatgui/transport/utun_node.cpp

@ -163,12 +163,8 @@ void UtunNode::runLoop() {
else if (lvl == "debug") dl = DEBUG_LEVEL_DEBUG;
else if (lvl == "trace") dl = DEBUG_LEVEL_TRACE;
g_debug_config.level = dl;
g_debug_config.console_level = dl;
g_debug_config.file_level = dl;
} else {
g_debug_config.level = DEBUG_LEVEL_INFO;
g_debug_config.console_level = DEBUG_LEVEL_INFO;
g_debug_config.file_level = DEBUG_LEVEL_INFO;
}
/* chatgui defaults: suppress spam, verbose for our categories */

Loading…
Cancel
Save