From a8c971aad48df815c784e74947f9799b8afc5dd9 Mon Sep 17 00:00:00 2001
From: Andrey Volk <andywolk@gmail.com>
Date: Thu, 4 Mar 2021 01:29:10 +0300
Subject: [PATCH] [Core] Add exclude-error-log-from-xml-cdr config parameter
 and exclude_error_log_from_xml_cdr global variable.

---
 src/switch_core.c | 7 +++++++
 src/switch_ivr.c  | 3 ++-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/switch_core.c b/src/switch_core.c
index c3ddc5124e..50ce348c95 100644
--- a/src/switch_core.c
+++ b/src/switch_core.c
@@ -2309,6 +2309,13 @@ static void switch_load_core_config(const char *file)
 						switch_core_set_variable("spawn_instead_of_system", "false");
 					}
 #endif
+				} else if (!strcasecmp(var, "exclude-error-log-from-xml-cdr") && !zstr(val)) {
+					int v = switch_true(val);
+					if (v) {
+						switch_core_set_variable("exclude_error_log_from_xml_cdr", "true");
+					} else {
+						switch_core_set_variable("exclude_error_log_from_xml_cdr", "false");
+					}
 				} else if (!strcasecmp(var, "min-idle-cpu") && !zstr(val)) {
 					switch_core_min_idle_cpu(atof(val));
 				} else if (!strcasecmp(var, "tipping-point") && !zstr(val)) {
diff --git a/src/switch_ivr.c b/src/switch_ivr.c
index 51875e4c25..4f9d2d0cbd 100644
--- a/src/switch_ivr.c
+++ b/src/switch_ivr.c
@@ -2690,6 +2690,7 @@ SWITCH_DECLARE(int) switch_ivr_set_xml_call_stats(switch_xml_t xml, switch_core_
 	int loff = 0;
 	switch_rtp_stats_t *stats = switch_core_media_get_stats(session, type, NULL);
 	char var_val[35] = "";
+	switch_bool_t exclude_error_log_from_xml_cdr = switch_true(switch_core_get_variable("exclude_error_log_from_xml_cdr"));
 
 	if (!stats) return off;
 
@@ -2727,7 +2728,7 @@ SWITCH_DECLARE(int) switch_ivr_set_xml_call_stats(switch_xml_t xml, switch_core_
 	add_stat_double(x_in, stats->inbound.mos, "mos");
 
 
-	if (stats->inbound.error_log) {
+	if (stats->inbound.error_log && !exclude_error_log_from_xml_cdr) {
 		switch_xml_t x_err_log, x_err;
 		switch_error_period_t *ep;
 		int eoff = 0;