@@ -49,54 +49,8 @@ static int providerLogLevel = WP_LOG_LEVEL_ALL;
4949 * in wolfProv_LogComponents. Default components include all. */
5050static int providerLogComponents = WP_LOG_COMPONENTS_ALL ;
5151
52- #ifdef WOLFPROV_LOG_FILE
53- /* Persistent file handle for logging to file */
54- static XFILE * logFileHandle = NULL ;
55- #endif
56-
5752#endif /* WOLFPROV_DEBUG */
5853
59- /**
60- * Initialize the persistent log file handle.
61- * Called once during provider initialization.
62- *
63- * @return 0 on success, negative value on failure.
64- */
65-
66- int wp_log_file_init (void )
67- {
68- #if defined(WOLFPROV_LOG_FILE ) && defined(WOLFPROV_DEBUG )
69- if (logFileHandle == NULL ) {
70- logFileHandle = XFOPEN (WOLFPROV_LOG_FILE , "a" );
71- if (logFileHandle ) {
72- XFPRINTF (stderr , "wolfProvider: Using log file %s\n" , WOLFPROV_LOG_FILE );
73- fflush (stderr );
74- }
75- else {
76- /* File open failed - will fall back to stderr on first log */
77- XFPRINTF (stderr , "wolfProvider: Failed to open log file %s\n" , WOLFPROV_LOG_FILE );
78- return -1 ;
79- }
80- }
81- #endif /* WOLFPROV_LOG_FILE && WOLFPROV_DEBUG */
82- return 0 ;
83- }
84-
85- /**
86- * Cleanup the persistent log file handle.
87- * Called during provider teardown.
88- */
89- void wp_log_file_cleanup (void )
90- {
91- #if defined(WOLFPROV_LOG_FILE ) && defined(WOLFPROV_DEBUG )
92- if (logFileHandle != NULL ) {
93- XFPRINTF (stderr , "wolfProvider: Closing log file %s\n" , WOLFPROV_LOG_FILE );
94- XFCLOSE (logFileHandle );
95- logFileHandle = NULL ;
96- }
97- #endif /* WOLFPROV_LOG_FILE && WOLFPROV_DEBUG */
98- }
99-
10054/**
10155 * Registers wolfProv logging callback.
10256 * Callback will be used by wolfProv for debug/log messages.
@@ -220,24 +174,33 @@ static void wolfprovider_log(const int logLevel, const int component,
220174 printf ("%s\n" , logMessage );
221175#elif defined(WOLFPROV_LOG_FILE )
222176 {
177+ /* Persistent file handle for logging to file */
178+ static XFILE * logFileHandle = NULL ;
223179 /* Flag to track if we've already reported file open failure to avoid spam */
224180 static int logFileErrorReported = 0 ;
225181
226- if (logFileHandle != NULL ) {
227- XFWRITE (logMessage , strlen (logMessage ), 1 , logFileHandle );
228- XFWRITE ("\n" , 1 , 1 , logFileHandle );
229- XFFLUSH (logFileHandle );
230- } else {
231- /* Only report file error once to avoid spam */
232- if (!logFileErrorReported ) {
233- XFPRINTF (stderr , "wolfProvider: Log file not open: %s, "
234- "falling back to stderr\n" ,
235- WOLFPROV_LOG_FILE );
236- logFileErrorReported = 1 ;
182+ if (logFileHandle == NULL ) {
183+ logFileHandle = XFOPEN (WOLFPROV_LOG_FILE , "a" );
184+ if (logFileHandle ) {
185+ XFPRINTF (stderr , "wolfProvider: Using log file %s\n" , WOLFPROV_LOG_FILE );
186+ fflush (stderr );
187+ }
188+ else {
189+ /* Fall back to stderr when file open fails */
190+ logFileHandle = stderr ;
191+ /* Only report file error once to avoid spam */
192+ if (!logFileErrorReported ) {
193+ logFileErrorReported = 1 ;
194+ XFPRINTF (stderr , "wolfProvider: Log file not open: %s, "
195+ "falling back to stderr\n" ,
196+ WOLFPROV_LOG_FILE );
197+ }
237198 }
238- XFWRITE (logMessage , strlen (logMessage ), 1 , stderr );
239- XFWRITE ("\n" , 1 , 1 , stderr );
240199 }
200+
201+ XFWRITE (logMessage , strlen (logMessage ), 1 , logFileHandle );
202+ XFWRITE ("\n" , 1 , 1 , logFileHandle );
203+ XFFLUSH (logFileHandle );
241204 }
242205#else
243206 XFPRINTF (stderr , "%s\n" , logMessage );
0 commit comments