< prev index next >
src/jdk.accessibility/windows/native/common/AccessBridgeDebug.cpp
Print this page
*** 29,43 ****
--- 29,64 ----
#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,96 ****
--- 108,123 ----
#ifdef SEND_TO_CONSOLE
printf(buf);
printf("\r\n");
#endif
#endif
+ if (logFP) {
+ va_list args;
+ va_start(args, msg);
+ fprintf(logFP, msg, args);
+ va_end(args);
+ }
}
/**
* Send Java debugging info to the appropriate place
*/
*** 107,116 ****
--- 134,149 ----
#ifdef SEND_TO_CONSOLE
printf(buf);
printf("\r\n");
#endif
#endif
+ if (logFP) {
+ va_list args;
+ va_start(args, msg);
+ fprintf(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,137 ****
--- 161,176 ----
#ifdef SEND_TO_CONSOLE
printf(buf);
printf("\r\n");
#endif
#endif
+ if (logFP) {
+ va_list args;
+ va_start(args, msg);
+ fwprintf(logFP, msg, args);
+ va_end(args);
+ }
}
/**
* Wide version of the method to send Java debugging info to the appropriate place
*/
*** 150,158 ****
--- 189,203 ----
#ifdef SEND_TO_CONSOLE
printf(buf);
printf("\r\n");
#endif
#endif
+ if (logFP){
+ va_list args;
+ va_start(args, msg);
+ fwprintf(logFP, msg, args);
+ va_end(args);
+ }
}
#ifdef __cplusplus
}
#endif
< prev index next >