1
This commit is contained in:
1 parent
35cb85a537
commit
8271ec3ecb
3 files changed
+31
-23
No files matched your search
@@ -131,6 +131,26 @@ void debug_set_category_level_by_name(const char* category_name, const char* lev
|
||||
debug_set_category_level(cat, lvl);
|
||||
}
|
||||
|
||||
int debug_apply_category_config(const char* category_name, const char* level_name) {
|
||||
if (!category_name || !level_name) return -1;
|
||||
debug_category_t cat = get_category_by_name(category_name);
|
||||
if (cat == DEBUG_CATEGORY_NONE) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_CONFIG, "Unknown debug category '%s'", category_name);
|
||||
return -1;
|
||||
}
|
||||
debug_level_t lvl = debug_level_from_name(level_name);
|
||||
debug_set_category_level(cat, lvl);
|
||||
DEBUG_INFO(DEBUG_CATEGORY_CONFIG, "Applied per-category debug: %s=%s", category_name, level_name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void debug_apply_global_level(const char* level_name) {
|
||||
if (!level_name || !*level_name) return;
|
||||
debug_level_t level = debug_level_from_name(level_name);
|
||||
debug_set_level(level);
|
||||
DEBUG_INFO(DEBUG_CATEGORY_CONFIG, "Applied global debug_level: %s", level_name);
|
||||
}
|
||||
|
||||
/* Get category name for logging */
|
||||
const char* debug_get_category_name(debug_category_t category_idx) {
|
||||
switch (category_idx) {
|
||||
|
||||
@@ -135,6 +135,12 @@ debug_level_t debug_level_from_name(const char* name);
|
||||
/* Set category level using text names (main API) */
|
||||
void debug_set_category_level_by_name(const char* category_name, const char* level_name);
|
||||
|
||||
/* Apply full category config with error reporting */
|
||||
int debug_apply_category_config(const char* category_name, const char* level_name);
|
||||
|
||||
/* Apply global debug level from text name */
|
||||
void debug_apply_global_level(const char* level_name);
|
||||
|
||||
/* Format and output debug message (internal use by macros) */
|
||||
void debug_output(debug_level_t level, debug_category_t category_idx,
|
||||
const char* function, const char* file, int line,
|
||||
|
||||
+5
-23
@@ -142,33 +142,15 @@ struct UTUN_INSTANCE* utun_instance_create(struct UASYNC* ua, const char *config
|
||||
|
||||
// Apply debug level from config
|
||||
if (config->global.debug_level[0]) {
|
||||
debug_level_t level = DEBUG_LEVEL_INFO;
|
||||
if (strcmp(config->global.debug_level, "error") == 0) level = DEBUG_LEVEL_ERROR;
|
||||
else if (strcmp(config->global.debug_level, "warn") == 0) level = DEBUG_LEVEL_WARN;
|
||||
else if (strcmp(config->global.debug_level, "info") == 0) level = DEBUG_LEVEL_INFO;
|
||||
else if (strcmp(config->global.debug_level, "debug") == 0) level = DEBUG_LEVEL_DEBUG;
|
||||
else if (strcmp(config->global.debug_level, "trace") == 0) level = DEBUG_LEVEL_TRACE;
|
||||
debug_set_level(level);
|
||||
DEBUG_INFO(DEBUG_CATEGORY_CONFIG, "Applied debug_level from config: %s", config->global.debug_level);
|
||||
debug_apply_global_level(config->global.debug_level);
|
||||
}
|
||||
|
||||
// Apply per-category debug levels from [debug] section
|
||||
for (int i = 0; i < config->global.debug_levels.count; i++) {
|
||||
const char* cat_name = config->global.debug_levels.category[i];
|
||||
const char* lvl_str = config->global.debug_levels.level[i];
|
||||
|
||||
debug_category_t cat = get_category_by_name(cat_name);
|
||||
if (cat != DEBUG_CATEGORY_NONE) {
|
||||
debug_level_t lvl = DEBUG_LEVEL_NONE;
|
||||
if (strcmp(lvl_str, "error") == 0) lvl = DEBUG_LEVEL_ERROR;
|
||||
else if (strcmp(lvl_str, "warn") == 0) lvl = DEBUG_LEVEL_WARN;
|
||||
else if (strcmp(lvl_str, "info") == 0) lvl = DEBUG_LEVEL_INFO;
|
||||
else if (strcmp(lvl_str, "debug") == 0) lvl = DEBUG_LEVEL_DEBUG;
|
||||
else if (strcmp(lvl_str, "trace") == 0) lvl = DEBUG_LEVEL_TRACE;
|
||||
|
||||
debug_set_category_level(cat, lvl);
|
||||
DEBUG_INFO(DEBUG_CATEGORY_CONFIG, "Applied per-category debug: %s=%s", cat_name, lvl_str);
|
||||
}
|
||||
debug_apply_category_config(
|
||||
config->global.debug_levels.category[i],
|
||||
config->global.debug_levels.level[i]
|
||||
);
|
||||
}
|
||||
|
||||
// Allocate instance
|
||||
|
||||
Reference in new issue
Block a user