Skip to content

Commit e7a9ab4

Browse files
committed
Add option for debug output to default to silent
1 parent 5790a03 commit e7a9ab4

File tree

5 files changed

+60
-2
lines changed

5 files changed

+60
-2
lines changed

configure.ac

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,16 @@ AS_IF([test "$ax_enable_debug" = "yes"],
7373
[AM_CFLAGS="$DEBUG_CFLAGS $AM_CFLAGS"],
7474
[])
7575

76+
# Debug silent mode - logging compiled in but silent until env vars activate
77+
AC_ARG_ENABLE([debug-silent],
78+
[AS_HELP_STRING([--enable-debug-silent],[Debug logging compiled in but silent by default. Use WOLFPROV_LOG_LEVEL and WOLFPROV_LOG_COMPONENTS env vars to enable at runtime (default: disabled)])],
79+
[ ENABLED_DEBUG_SILENT=$enableval ],
80+
[ ENABLED_DEBUG_SILENT=no ]
81+
)
82+
83+
AS_IF([test "$ENABLED_DEBUG_SILENT" = "yes"],
84+
[AM_CFLAGS="$AM_CFLAGS -DWOLFPROV_DEBUG_SILENT"])
85+
7686
# COVERAGE
7787
COVERAGE_CFLAGS="--coverage"
7888
AX_COVERAGE
@@ -207,6 +217,7 @@ echo " * Host CPU: $host_cpu"
207217
echo " * C Compiler: $CC"
208218
echo " * C Flags: $CFLAGS"
209219
echo " * Debug enabled: $ax_enable_debug"
220+
echo " * Debug silent mode: $ENABLED_DEBUG_SILENT"
210221
echo
211222
echo " Features "
212223
echo " * User settings: $ENABLED_USERSETTINGS"

include/wolfprovider/wp_logging.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@
5656
/* wolfProv debug logging support can be compiled in by defining
5757
* WOLFPROV_DEBUG or by using the --enable-debug configure option.
5858
*
59+
* By default, when debug is enabled, logging is active immediately.
60+
* Use --enable-debug-silent to compile in debug support but keep it
61+
* silent by default. In silent mode, logging is only activated when
62+
* WOLFPROV_LOG_LEVEL or WOLFPROV_LOG_COMPONENTS environment variables
63+
* are set at runtime.
64+
*
5965
* wolfProv supports the log levels as mentioned in wolfProv_LogLevels
6066
* enum below. The default logging level when debug logging is compiled in
6167
* and enabled at runtime is WP_LOG_LEVEL_DEFAULT.

scripts/build-wolfprovider.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ show_help() {
2727
echo " Note: Requires --replace-default. Only for test builds, not for production."
2828
echo " --leave-silent Enable leave silent mode to suppress logging of return 0 in probing functions where expected failures may occur."
2929
echo " Note: This only affects logging; the calling function is still responsible for handling all return values appropriately."
30+
echo " --debug-silent Debug logging compiled in but silent by default. Use WOLFPROV_LOG_LEVEL and WOLFPROV_LOG_COMPONENTS env vars to enable at runtime. Requires --debug."
3031
echo " --enable-seed-src Enable SEED-SRC entropy source with /dev/urandom caching for fork-safe entropy."
3132
echo " Note: This also enables WC_RNG_SEED_CB in wolfSSL."
3233
echo ""
@@ -39,6 +40,7 @@ show_help() {
3940
echo " WOLFPROV_CLEAN If set to 1, run make clean in OpenSSL, wolfSSL, and wolfProvider"
4041
echo " WOLFPROV_DISTCLEAN If set to 1, remove the source and install directories of OpenSSL, wolfSSL, and wolfProvider"
4142
echo " WOLFPROV_DEBUG If set to 1, builds OpenSSL, wolfSSL, and wolfProvider with debug options enabled"
43+
echo " WOLFPROV_DEBUG_SILENT If set to 1, debug logging is silent by default (requires WOLFPROV_DEBUG=1)"
4244
echo " WOLFPROV_LOG_FILE Path to log file for wolfProvider debug output (alternative to stderr)"
4345
echo " WOLFPROV_QUICKTEST If set to 1, disables some tests in the test suite to increase test speed"
4446
echo " WOLFPROV_DISABLE_ERR_TRACE If set to 1, wolfSSL will not be configured with --enable-debug-trace-errcodes=backtrace"
@@ -132,6 +134,9 @@ for arg in "$@"; do
132134
--leave-silent)
133135
WOLFPROV_LEAVE_SILENT=1
134136
;;
137+
--debug-silent)
138+
WOLFPROV_DEBUG_SILENT=1
139+
;;
135140
--enable-seed-src)
136141
WOLFPROV_SEED_SRC=1
137142
;;
@@ -154,6 +159,12 @@ if [ "${WOLFPROV_LEAVE_SILENT}" = "1" ] && [ -z "$WOLFPROV_DEBUG" ] && [ -z "$de
154159
exit 1
155160
fi
156161

162+
# Check if --debug-silent was used without debug mode
163+
if [ "${WOLFPROV_DEBUG_SILENT}" = "1" ] && [ -z "$WOLFPROV_DEBUG" ] && [ -z "$debug" ]; then
164+
echo "Error: --debug-silent requires --debug to be set."
165+
exit 1
166+
fi
167+
157168
if [ -n "$WOLFPROV_LOG_FILE" ] && [ -z "$WOLFPROV_DEBUG" ]; then
158169
echo "Error: --debug-log requires --debug to be set."
159170
exit 1

scripts/utils-wolfprovider.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ install_wolfprov() {
114114
WOLFPROV_CONFIG_CFLAGS="${WOLFPROV_CONFIG_CFLAGS} -DWOLFPROV_LEAVE_SILENT_MODE"
115115
fi
116116

117+
if [ "${WOLFPROV_DEBUG_SILENT}" = "1" ]; then
118+
WOLFPROV_CONFIG_OPTS+=" --enable-debug-silent"
119+
fi
120+
117121
if [ -n "${WOLFPROV_LOG_FILE}" ]; then
118122
WOLFPROV_CONFIG_CFLAGS="${WOLFPROV_CONFIG_CFLAGS} -DWOLFPROV_LOG_FILE=\\\"${WOLFPROV_LOG_FILE}\\\""
119123
fi

src/wp_logging.c

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,16 @@
3737
static wolfProv_Logging_cb log_function = NULL;
3838

3939
/* Flag indicating if logging is enabled, controlled via
40-
* wolfProv_Debugging_ON() and wolfProv_Debugging_OFF() */
40+
* wolfProv_Debugging_ON() and wolfProv_Debugging_OFF(). */
4141
static int loggingEnabled = 1;
4242

43+
#ifdef WOLFPROV_DEBUG_SILENT
44+
/* Silent mode gate - when active, blocks all logging output regardless of
45+
* loggingEnabled. Only deactivated when WOLFPROV_LOG_LEVEL or
46+
* WOLFPROV_LOG_COMPONENTS environment variables are set at runtime. */
47+
static int silentModeActive = 1;
48+
#endif
49+
4350
/* Logging level. Bitmask of logging levels in wolfProv_LogLevels.
4451
* Default log level includes error, enter/leave, and info. Does not turn on
4552
* verbose by default. */
@@ -121,6 +128,13 @@ int wolfProv_LogInit(void)
121128
char* logLevelStr = XGETENV("WOLFPROV_LOG_LEVEL");
122129
char* logComponentsStr = XGETENV("WOLFPROV_LOG_COMPONENTS");
123130

131+
#ifdef WOLFPROV_DEBUG_SILENT
132+
/* In silent mode, deactivate the silent gate only if env vars are set */
133+
if (logLevelStr != NULL || logComponentsStr != NULL) {
134+
silentModeActive = 0;
135+
}
136+
#endif
137+
124138
if (logLevelStr != NULL) {
125139
if (wolfProv_TokenParse(logLevelStr, "()| \t", wolfProv_LogLevelToMask,
126140
&level) == 0) {
@@ -201,11 +215,23 @@ int wolfProv_SetLogComponents(int componentMask)
201215
* @param logLevel [IN] Log level.
202216
*/
203217
WP_PRINTF_FUNC(3, 0)
204-
static void wolfprovider_log(const int component, const int logLevel,
218+
static void wolfprovider_log(const int component, const int logLevel,
205219
const char* fmt, va_list vlist)
206220
{
207221
char logMessage[WOLFPROV_MAX_LOG_WIDTH];
208222

223+
/* Don't log if logging is disabled */
224+
if (!loggingEnabled) {
225+
return;
226+
}
227+
228+
#ifdef WOLFPROV_DEBUG_SILENT
229+
/* In silent mode, block all output until env vars unlock it */
230+
if (silentModeActive) {
231+
return;
232+
}
233+
#endif
234+
209235
/* Don't log messages that do not match our current logging level */
210236
if ((providerLogLevel & logLevel) != logLevel) {
211237
return;

0 commit comments

Comments
 (0)