Skip to content

Commit 720ba03

Browse files
author
Test User
committed
Add option to force debug output to log file
1 parent 655b63d commit 720ba03

File tree

5 files changed

+31
-0
lines changed

5 files changed

+31
-0
lines changed

include/wolfprovider/wp_logging.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@
7878
* WOLFPROV_LOG_PRINTF Define to Use printf instead of fprintf (to stderr)
7979
* for logs. Not applicable if using WOLFPROV_USER_LOG
8080
* or custom logging callback.
81+
* WOLFPROV_LOG_FILE Define to specify a file path for debug output instead
82+
* of stderr. This is typically set via --debug-log=FILE
83+
* build script argument.
8184
*
8285
* COMPILE-TIME MACRO CONFIGURATIONS:
8386
* Define these macros in this header to control logging at compile time:

scripts/build-wolfprovider.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ show_help() {
1010
echo " --clean Run make clean in OpenSSL, wolfSSL, and wolfProvider"
1111
echo " --distclean Remove source and install directories of OpenSSL, wolfSSL, and wolfProvider"
1212
echo " --debug Builds OpenSSL, wolfSSL, and WolfProvider with debugging enabled. This is the same as setting WOLFPROV_DEBUG=1"
13+
echo " --debug-log=FILE Force all wolfProvider debug output to specified log file instead of stderr/stdout (FILE = path to log file you want to use)"
1314
echo " --debug-asn-template Enable debug information for asn within wolfSSL"
1415
echo " --disable-err-trace No debug trace messages from library errors in wolfSSL"
1516
echo " --openssl-ver=VER Which version of OpenSSL to clone"
@@ -35,6 +36,7 @@ show_help() {
3536
echo " WOLFPROV_CLEAN If set to 1, run make clean in OpenSSL, wolfSSL, and wolfProvider"
3637
echo " WOLFPROV_DISTCLEAN If set to 1, remove the source and install directories of OpenSSL, wolfSSL, and wolfProvider"
3738
echo " WOLFPROV_DEBUG If set to 1, builds OpenSSL, wolfSSL, and wolfProvider with debug options enabled"
39+
echo " WOLFPROV_LOG_FILE Path to log file for wolfProvider debug output (alternative to stderr)"
3840
echo " WOLFPROV_QUICKTEST If set to 1, disables some tests in the test suite to increase test speed"
3941
echo " WOLFPROV_DISABLE_ERR_TRACE If set to 1, wolfSSL will not be configured with --enable-debug-trace-errcodes=backtrace"
4042
echo " WOLFPROV_LEAVE_SILENT If set to 1, suppress logging of return 0 in functions where return 0 is expected behavior sometimes."
@@ -59,6 +61,14 @@ for arg in "$@"; do
5961
--debug)
6062
WOLFPROV_DEBUG=1
6163
;;
64+
--debug-log=*)
65+
IFS='=' read -r trash log_file <<< "$arg"
66+
if [ -z "$log_file" ]; then
67+
echo "No file path given for --debug-log"
68+
args_wrong+="$arg, "
69+
fi
70+
WOLFPROV_LOG_FILE="$log_file"
71+
;;
6272
--debug-asn-template)
6373
WOLFSSL_DEBUG_ASN_TEMPLATE=1
6474
;;

scripts/utils-openssl.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,8 @@ install_openssl() {
342342
}
343343

344344
init_openssl() {
345+
WOLFPROV_BUILD_DEBIAN=${WOLFPROV_BUILD_DEBIAN:-0}
346+
345347
if [ $WOLFPROV_BUILD_DEBIAN -eq 1 ]; then
346348
install_openssl_deb
347349
else

scripts/utils-wolfprovider.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ install_wolfprov() {
100100
WOLFPROV_CONFIG_CFLAGS="${WOLFPROV_CONFIG_CFLAGS} -DWOLFPROV_LEAVE_SILENT_MODE"
101101
fi
102102

103+
if [ -n "${WOLFPROV_LOG_FILE}" ]; then
104+
WOLFPROV_CONFIG_CFLAGS="${WOLFPROV_CONFIG_CFLAGS} -DWOLFPROV_LOG_FILE=\\\"${WOLFPROV_LOG_FILE}\\\""
105+
fi
106+
103107
./configure ${WOLFPROV_CONFIG_OPTS} CFLAGS="${WOLFPROV_CONFIG_CFLAGS}" >>$LOG_FILE 2>&1
104108
RET=$?
105109
if [ $RET != 0 ]; then

src/wp_logging.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,18 @@ static void wolfprovider_log(const int logLevel, const int component,
173173
WOLFPROV_USER_LOG(logMessage);
174174
#elif defined(WOLFPROV_LOG_PRINTF)
175175
printf("%s\n", logMessage);
176+
#elif defined(WOLFPROV_LOG_FILE)
177+
{
178+
FILE* logFile = fopen(WOLFPROV_LOG_FILE, "a");
179+
if (logFile != NULL) {
180+
fprintf(logFile, "%s\n", logMessage);
181+
fclose(logFile);
182+
} else {
183+
fprintf(stderr, "wolfProvider: Failed to open log file %s\n",
184+
WOLFPROV_LOG_FILE);
185+
fprintf(stderr, "%s\n", logMessage);
186+
}
187+
}
176188
#else
177189
fprintf(stderr, "%s\n", logMessage);
178190
#endif

0 commit comments

Comments
 (0)