From c226475c2920fe8992b5ac025e850e5a927433c1 Mon Sep 17 00:00:00 2001
From: "Rob Swindell (on Windows 11)" <rob@synchro.net>
Date: Wed, 13 Nov 2024 19:46:34 -0800
Subject: [PATCH] Allow a separate log level for the event thread of the
 terminal server

So you want to debug (timed) events, but don't want to get debug-spew in your
terminal server log output? Now you can: By default, the event thread log
level will be the same as the terminal server, but now you can override this
by setting [BBS] EventLogLevel in the sbbs.ini file or set it in
SCFG->Servers->Terminal Server->Event Log Level.
---
 src/sbbs3/main.cpp        |  2 +-
 src/sbbs3/sbbs_ini.c      |  7 +++++++
 src/sbbs3/scfg/scfgsrvr.c | 13 ++++++++++---
 src/sbbs3/startup.h       |  1 +
 4 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/src/sbbs3/main.cpp b/src/sbbs3/main.cpp
index 24eb7e0cb8..bd60e89e2f 100644
--- a/src/sbbs3/main.cpp
+++ b/src/sbbs3/main.cpp
@@ -266,7 +266,7 @@ int eputs(int level, const char *str)
 			startup->errormsg(startup->cbdata, level, errmsg);
 	}
 
-	if(startup==NULL || startup->event_lputs==NULL || level > startup->log_level)
+	if(startup==NULL || startup->event_lputs==NULL || level > startup->event_log_level)
 		return(0);
 
 	return(startup->event_lputs(startup->event_cbdata,level,str));
diff --git a/src/sbbs3/sbbs_ini.c b/src/sbbs3/sbbs_ini.c
index 7503500a20..96cae8eb98 100644
--- a/src/sbbs3/sbbs_ini.c
+++ b/src/sbbs3/sbbs_ini.c
@@ -47,6 +47,7 @@ static const char*	strMaxSFTPInactivity="MaxSFTPInactivity";
 static const char*	strMaxConConn="MaxConcurrentConnections";
 static const char*	strHostName="HostName";
 static const char*	strLogLevel="LogLevel";
+static const char*	strEventLogLevel="EventLogLevel";
 static const char*	strTLSErrorLevel="TLSErrorLevel";
 static const char*	strBindRetryCount="BindRetryCount";
 static const char*	strBindRetryDelay="BindRetryDelay";
@@ -504,6 +505,8 @@ void sbbs_read_ini(
 
 		bbs->log_level
 			=iniGetLogLevel(list,section,strLogLevel,global->log_level);
+		bbs->event_log_level
+			=iniGetLogLevel(list,section,strEventLogLevel,bbs->log_level);
 		bbs->options
 			=iniGetBitField(list,section,strOptions,bbs_options
 				,BBS_OPT_XTRN_MINIMIZED);
@@ -957,6 +960,10 @@ bool sbbs_write_ini(
 			iniRemoveValue(lp,section,strLogLevel);
 		else if(!iniSetLogLevel(lp,section,strLogLevel,bbs->log_level,&style))
 			break;
+		if(bbs->event_log_level==bbs->log_level)
+			iniRemoveValue(lp,section,strEventLogLevel);
+		else if(!iniSetLogLevel(lp,section,strEventLogLevel,bbs->event_log_level,&style))
+			break;
 
 		/* JavaScript operating parameters */
 		if(!sbbs_set_js_settings(lp,section,&bbs->js,&global->js,&style))
diff --git a/src/sbbs3/scfg/scfgsrvr.c b/src/sbbs3/scfg/scfgsrvr.c
index 3f94b98cc9..8e58b470b2 100644
--- a/src/sbbs3/scfg/scfgsrvr.c
+++ b/src/sbbs3/scfg/scfgsrvr.c
@@ -566,6 +566,8 @@ static void termsrvr_cfg(void)
 		snprintf(opt[i++], MAX_OPLN, "%-30s%s", "Execute Timed Events", startup.options & BBS_OPT_NO_EVENTS ? "No" : "Yes");
 		snprintf(opt[i++], MAX_OPLN, "%-30s%s", "Execute QWK-related Events"
 			,startup.options & BBS_OPT_NO_EVENTS ? "N/A" : startup.options & BBS_OPT_NO_QWK_EVENTS ? "No" : "Yes");
+		snprintf(opt[i++], MAX_OPLN, "%-30s%s", "Event Log Level"
+			,startup.options & BBS_OPT_NO_EVENTS ? "N/A" : iniLogLevelStringList()[startup.event_log_level]);
 		snprintf(opt[i++], MAX_OPLN, "%-30s%s", "Lookup Client Hostname", startup.options & BBS_OPT_NO_HOST_LOOKUP ? "No" : "Yes");
 		snprintf(opt[i++], MAX_OPLN, "%-30s%s", "Login Requirements", startup.login_ars);
 		strcpy(opt[i++], "JavaScript Settings...");
@@ -693,15 +695,20 @@ static void termsrvr_cfg(void)
 				startup.options ^= BBS_OPT_NO_QWK_EVENTS;
 				break;
 			case 16:
-				startup.options ^= BBS_OPT_NO_HOST_LOOKUP;
+				if(startup.options & BBS_OPT_NO_EVENTS)
+					break;
+				uifc.list(WIN_MID|WIN_SAV, 0, 0, 0, &startup.event_log_level, 0, "Event Log Level", iniLogLevelStringList());
 				break;
 			case 17:
-				getar("Terminal Server Login", startup.login_ars);
+				startup.options ^= BBS_OPT_NO_HOST_LOOKUP;
 				break;
 			case 18:
-				js_startup_cfg(&startup.js);
+				getar("Terminal Server Login", startup.login_ars);
 				break;
 			case 19:
+				js_startup_cfg(&startup.js);
+				break;
+			case 20:
 				login_attempt_cfg(&startup.login_attempt);
 				break;
 			default:
diff --git a/src/sbbs3/startup.h b/src/sbbs3/startup.h
index d4908aa3eb..24ca868e9f 100644
--- a/src/sbbs3/startup.h
+++ b/src/sbbs3/startup.h
@@ -132,6 +132,7 @@ typedef struct {
 	uint16_t	ssh_port;
 	uint16_t	ssh_connect_timeout;
 	int			ssh_error_level;
+	int			event_log_level;
 	uint16_t	outbuf_highwater_mark;	/* output block size control */
 	uint16_t	outbuf_drain_timeout;
 	struct in_addr outgoing4;
-- 
GitLab