v0.7.4 - Remove excessive debug logging from entire codebase - preserve user-facing error logging
This commit is contained in:
@@ -209,12 +209,7 @@ int add_subscription_to_manager(subscription_t* sub) {
|
||||
|
||||
// Log subscription creation to database
|
||||
log_subscription_created(sub);
|
||||
|
||||
char debug_msg[256];
|
||||
snprintf(debug_msg, sizeof(debug_msg), "Added subscription '%s' (total: %d)",
|
||||
sub->id, g_subscription_manager.total_subscriptions);
|
||||
log_info(debug_msg);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -242,12 +237,7 @@ int remove_subscription_from_manager(const char* sub_id, struct lws* wsi) {
|
||||
|
||||
// Update events sent counter before freeing
|
||||
update_subscription_events_sent(sub_id, sub->events_sent);
|
||||
|
||||
char debug_msg[256];
|
||||
snprintf(debug_msg, sizeof(debug_msg), "Removed subscription '%s' (total: %d)",
|
||||
sub_id, g_subscription_manager.total_subscriptions);
|
||||
log_info(debug_msg);
|
||||
|
||||
|
||||
free_subscription(sub);
|
||||
return 0;
|
||||
}
|
||||
@@ -274,34 +264,24 @@ int event_matches_filter(cJSON* event, subscription_filter_t* filter) {
|
||||
if (filter->kinds && cJSON_IsArray(filter->kinds)) {
|
||||
cJSON* event_kind = cJSON_GetObjectItem(event, "kind");
|
||||
if (!event_kind || !cJSON_IsNumber(event_kind)) {
|
||||
log_info("DEBUG FILTER: kinds filter present but event has no valid kind");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int event_kind_val = (int)cJSON_GetNumberValue(event_kind);
|
||||
int kind_match = 0;
|
||||
|
||||
char debug_kinds_msg[256];
|
||||
snprintf(debug_kinds_msg, sizeof(debug_kinds_msg), "DEBUG FILTER: Checking kinds - event kind: %d", event_kind_val);
|
||||
log_info(debug_kinds_msg);
|
||||
|
||||
cJSON* kind_item = NULL;
|
||||
cJSON_ArrayForEach(kind_item, filter->kinds) {
|
||||
if (cJSON_IsNumber(kind_item)) {
|
||||
int filter_kind = (int)cJSON_GetNumberValue(kind_item);
|
||||
char debug_kind_check_msg[256];
|
||||
snprintf(debug_kind_check_msg, sizeof(debug_kind_check_msg), "DEBUG FILTER: Comparing event kind %d with filter kind %d", event_kind_val, filter_kind);
|
||||
log_info(debug_kind_check_msg);
|
||||
if (filter_kind == event_kind_val) {
|
||||
kind_match = 1;
|
||||
log_info("DEBUG FILTER: Kind match found!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!kind_match) {
|
||||
log_info("DEBUG FILTER: No kind match - filter fails");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -390,14 +370,9 @@ int event_matches_filter(cJSON* event, subscription_filter_t* filter) {
|
||||
if (filter->tag_filters && cJSON_IsObject(filter->tag_filters)) {
|
||||
cJSON* event_tags = cJSON_GetObjectItem(event, "tags");
|
||||
if (!event_tags || !cJSON_IsArray(event_tags)) {
|
||||
log_info("DEBUG FILTER: tag filters present but event has no valid tags array");
|
||||
return 0; // Event has no tags but filter requires tags
|
||||
}
|
||||
|
||||
char debug_tags_msg[256];
|
||||
snprintf(debug_tags_msg, sizeof(debug_tags_msg), "DEBUG FILTER: Checking tag filters - event has %d tags", cJSON_GetArraySize(event_tags));
|
||||
log_info(debug_tags_msg);
|
||||
|
||||
// Check each tag filter
|
||||
cJSON* tag_filter = NULL;
|
||||
cJSON_ArrayForEach(tag_filter, filter->tag_filters) {
|
||||
@@ -407,10 +382,6 @@ int event_matches_filter(cJSON* event, subscription_filter_t* filter) {
|
||||
|
||||
const char* tag_name = tag_filter->string + 1; // Skip the '#'
|
||||
|
||||
char debug_tag_filter_msg[256];
|
||||
snprintf(debug_tag_filter_msg, sizeof(debug_tag_filter_msg), "DEBUG FILTER: Checking tag filter #%s", tag_name);
|
||||
log_info(debug_tag_filter_msg);
|
||||
|
||||
if (!cJSON_IsArray(tag_filter)) {
|
||||
continue; // Tag filter must be an array
|
||||
}
|
||||
@@ -434,28 +405,16 @@ int event_matches_filter(cJSON* event, subscription_filter_t* filter) {
|
||||
const char* event_tag_name_str = cJSON_GetStringValue(event_tag_name);
|
||||
const char* event_tag_value_str = cJSON_GetStringValue(event_tag_value);
|
||||
|
||||
char debug_event_tag_msg[256];
|
||||
snprintf(debug_event_tag_msg, sizeof(debug_event_tag_msg), "DEBUG FILTER: Event tag: %s = %s", event_tag_name_str, event_tag_value_str);
|
||||
log_info(debug_event_tag_msg);
|
||||
|
||||
// Check if tag name matches
|
||||
if (strcmp(event_tag_name_str, tag_name) == 0) {
|
||||
char debug_tag_name_match_msg[256];
|
||||
snprintf(debug_tag_name_match_msg, sizeof(debug_tag_name_match_msg), "DEBUG FILTER: Tag name '%s' matches filter", tag_name);
|
||||
log_info(debug_tag_name_match_msg);
|
||||
|
||||
// Check if any of the filter values match this tag value
|
||||
cJSON* filter_value = NULL;
|
||||
cJSON_ArrayForEach(filter_value, tag_filter) {
|
||||
if (cJSON_IsString(filter_value)) {
|
||||
const char* filter_value_str = cJSON_GetStringValue(filter_value);
|
||||
char debug_filter_value_msg[256];
|
||||
snprintf(debug_filter_value_msg, sizeof(debug_filter_value_msg), "DEBUG FILTER: Comparing event tag value '%s' with filter value '%s'", event_tag_value_str, filter_value_str);
|
||||
log_info(debug_filter_value_msg);
|
||||
// Support prefix matching for tag values
|
||||
if (strncmp(event_tag_value_str, filter_value_str, strlen(filter_value_str)) == 0) {
|
||||
tag_match = 1;
|
||||
log_info("DEBUG FILTER: Tag value match found!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -468,9 +427,6 @@ int event_matches_filter(cJSON* event, subscription_filter_t* filter) {
|
||||
}
|
||||
|
||||
if (!tag_match) {
|
||||
char debug_tag_fail_msg[256];
|
||||
snprintf(debug_tag_fail_msg, sizeof(debug_tag_fail_msg), "DEBUG FILTER: Tag filter #%s failed - no match found", tag_name);
|
||||
log_info(debug_tag_fail_msg);
|
||||
return 0; // This tag filter didn't match, so the event doesn't match
|
||||
}
|
||||
}
|
||||
@@ -482,40 +438,17 @@ int event_matches_filter(cJSON* event, subscription_filter_t* filter) {
|
||||
// Check if an event matches any filter in a subscription (filters are OR'd together)
|
||||
int event_matches_subscription(cJSON* event, subscription_t* subscription) {
|
||||
if (!event || !subscription || !subscription->filters) {
|
||||
char debug_msg[256];
|
||||
snprintf(debug_msg, sizeof(debug_msg), "DEBUG MATCH: Subscription '%s' - invalid parameters (event: %p, subscription: %p, filters: %p)",
|
||||
subscription ? subscription->id : "NULL", event, subscription, subscription ? subscription->filters : NULL);
|
||||
log_info(debug_msg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
char debug_start_msg[256];
|
||||
snprintf(debug_start_msg, sizeof(debug_start_msg), "DEBUG MATCH: Checking subscription '%s' filters", subscription->id);
|
||||
log_info(debug_start_msg);
|
||||
|
||||
subscription_filter_t* filter = subscription->filters;
|
||||
int filter_index = 0;
|
||||
while (filter) {
|
||||
int filter_matches = event_matches_filter(event, filter);
|
||||
char debug_filter_msg[256];
|
||||
snprintf(debug_filter_msg, sizeof(debug_filter_msg), "DEBUG MATCH: Subscription '%s' filter %d - %s",
|
||||
subscription->id, filter_index, filter_matches ? "MATCHES" : "no match");
|
||||
log_info(debug_filter_msg);
|
||||
|
||||
if (filter_matches) {
|
||||
char debug_match_msg[256];
|
||||
snprintf(debug_match_msg, sizeof(debug_match_msg), "DEBUG MATCH: Subscription '%s' - MATCH FOUND", subscription->id);
|
||||
log_info(debug_match_msg);
|
||||
if (event_matches_filter(event, filter)) {
|
||||
return 1; // Match found (OR logic)
|
||||
}
|
||||
filter = filter->next;
|
||||
filter_index++;
|
||||
}
|
||||
|
||||
char debug_no_match_msg[256];
|
||||
snprintf(debug_no_match_msg, sizeof(debug_no_match_msg), "DEBUG MATCH: Subscription '%s' - NO MATCHES", subscription->id);
|
||||
log_info(debug_no_match_msg);
|
||||
|
||||
return 0; // No filters matched
|
||||
}
|
||||
|
||||
@@ -534,11 +467,6 @@ int broadcast_event_to_subscriptions(cJSON* event) {
|
||||
if (expiration_enabled && filter_responses) {
|
||||
time_t current_time = time(NULL);
|
||||
if (is_event_expired(event, current_time)) {
|
||||
char debug_msg[256];
|
||||
cJSON* event_id_obj = cJSON_GetObjectItem(event, "id");
|
||||
const char* event_id = event_id_obj ? cJSON_GetStringValue(event_id_obj) : "unknown";
|
||||
snprintf(debug_msg, sizeof(debug_msg), "Skipping broadcast of expired event: %.16s", event_id);
|
||||
log_info(debug_msg);
|
||||
return 0; // Don't broadcast expired events
|
||||
}
|
||||
}
|
||||
@@ -547,25 +475,8 @@ int broadcast_event_to_subscriptions(cJSON* event) {
|
||||
|
||||
pthread_mutex_lock(&g_subscription_manager.subscriptions_lock);
|
||||
|
||||
// Debug: Log total active subscriptions
|
||||
int total_active = 0;
|
||||
subscription_t* count_sub = g_subscription_manager.active_subscriptions;
|
||||
while (count_sub) {
|
||||
total_active++;
|
||||
count_sub = count_sub->next;
|
||||
}
|
||||
|
||||
char debug_total_msg[128];
|
||||
snprintf(debug_total_msg, sizeof(debug_total_msg), "DEBUG BROADCAST: Broadcasting event to %d total active subscriptions", total_active);
|
||||
log_info(debug_total_msg);
|
||||
|
||||
subscription_t* sub = g_subscription_manager.active_subscriptions;
|
||||
while (sub) {
|
||||
// Debug: Log each subscription being checked
|
||||
char debug_sub_msg[256];
|
||||
snprintf(debug_sub_msg, sizeof(debug_sub_msg), "DEBUG BROADCAST: Checking subscription '%s' (active: %d)", sub->id, sub->active);
|
||||
log_info(debug_sub_msg);
|
||||
|
||||
if (sub->active && event_matches_subscription(event, sub)) {
|
||||
// Create EVENT message for this subscription
|
||||
cJSON* event_msg = cJSON_CreateArray();
|
||||
@@ -606,15 +517,9 @@ int broadcast_event_to_subscriptions(cJSON* event) {
|
||||
|
||||
// Update global statistics
|
||||
g_subscription_manager.total_events_broadcast += broadcasts;
|
||||
|
||||
|
||||
pthread_mutex_unlock(&g_subscription_manager.subscriptions_lock);
|
||||
|
||||
if (broadcasts > 0) {
|
||||
char debug_msg[256];
|
||||
snprintf(debug_msg, sizeof(debug_msg), "Broadcasted event to %d subscriptions", broadcasts);
|
||||
log_info(debug_msg);
|
||||
}
|
||||
|
||||
|
||||
return broadcasts;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user