< prev index next >

src/jdk.accessibility/windows/native/common/AccessBridgeDebug.cpp

Print this page

        

@@ -29,15 +29,36 @@
 
 #include "AccessBridgeDebug.h"
 #include <stdarg.h>
 #include <stdio.h>
 #include <windows.h>
+#include <cstdlib>
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
+static FILE* logFP = nullptr;
+static char* filePath = nullptr;
+
+void initializeFileLogger() {
+    const char* var = "JAVA_ACCESSBRIDGE_LOGFILE";
+    filePath = getenv(var);
+    if (filePath != nullptr) {
+        logFP = fopen(filePath, "w");
+        if (logFP == nullptr) {
+            PrintDebugString("couldnot open file %s", filePath);
+        }
+    }
+}
+
+void finalizeFileLogger() {
+    if (logFP) {
+        fclose(logFP);
+        logFP = nullptr;
+    }
+}
 /**
  * print a GetLastError message
  */
 char *printError(char *msg) {
     LPVOID lpMsgBuf = NULL;

@@ -87,10 +108,16 @@
 #ifdef SEND_TO_CONSOLE
         printf(buf);
         printf("\r\n");
 #endif
 #endif
+        if (logFP) {
+            va_list args;
+            va_start(args, msg);
+            vfprintf(logFP, msg, args);
+            va_end(args);
+        }
     }
 
     /**
      * Send Java debugging info to the appropriate place
      */

@@ -107,10 +134,16 @@
 #ifdef SEND_TO_CONSOLE
         printf(buf);
         printf("\r\n");
 #endif
 #endif
+        if (logFP) {
+            va_list args;
+            va_start(args, msg);
+            vfprintf(logFP, msg, args);
+            va_end(args);
+        }
     }
     /**
      * Wide version of the method to send debugging info to the appropriate place
      */
     void wPrintDebugString(wchar_t *msg, ...) {

@@ -128,10 +161,16 @@
 #ifdef SEND_TO_CONSOLE
         printf(buf);
         printf("\r\n");
 #endif
 #endif
+        if (logFP) {
+            va_list args;
+            va_start(args, msg);
+            vfwprintf(logFP, msg, args);
+            va_end(args);
+        }
     }
 
     /**
      * Wide version of the method to send Java debugging info to the appropriate place
      */

@@ -150,9 +189,15 @@
 #ifdef SEND_TO_CONSOLE
         printf(buf);
         printf("\r\n");
 #endif
 #endif
+        if (logFP) {
+            va_list args;
+            va_start(args, msg);
+            vfwprintf(logFP, msg, args);
+            va_end(args);
+        }
     }
 #ifdef __cplusplus
 }
 #endif
< prev index next >