How to re-direct both Java and C++ console output to a file
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Yi_Lu
Posted On:   Wednesday, May 23, 2001 05:20 AM

I have some java classes that use a MSVC++6 native dll. Both my java classes and my native dll have function enter/exit trace statements (System.out.println in Java and std::cerr in native dll) and I can inspect those trace statements (in the correct order of function calls) on the console when I debug either from JBuilder or from MSVC++6 debugger. Now I want all my trace statements, both Java and C++, re-directed to a log file. So I implemented a java logger class that creates the log file 'myLog.txt', sets the System.out/System.err so that all Java trace go to that log file. In my native dll, I also re-directed all the trace to that log file through std::fstream("myLog.txt",ios::out|ios::app). The log seemed to catch all the Java trace (System.o   More>>

I have some java classes that use a MSVC++6 native dll. Both my java classes and my native dll have function enter/exit trace statements (System.out.println in Java and std::cerr in native dll) and I can inspect those trace statements (in the correct order of function calls) on the console when I debug either from JBuilder or from MSVC++6 debugger.
Now I want all my trace statements, both Java and C++, re-directed to a log file. So I implemented a java logger class that creates the log file 'myLog.txt', sets the System.out/System.err so that all Java trace go to that log file. In my native dll, I also re-directed all the trace to that log file through std::fstream("myLog.txt",ios::out|ios::app). The log seemed to catch all the Java trace (System.out and System.err) and native C++ trace (now through std::fstream).
The problem I found is that all the Java trace statements come before all the native C++ trace statements even though some of the native function calls are before some of the Java class function calls. Has anyone come across the same problem, or any workaround (since the console output is ok)?

   <<Less

Re: How to re-direct both Java and C++ console output to a file

Posted By:   Christopher_Schultz  
Posted On:   Wednesday, May 23, 2001 10:18 AM

Make sure that you are flushing the stream after you write your output to it. If you don't flush your stream, it may be buffered for quite a while before it's actually written to the disk.



It looks like what is happening is the native part of your app is being more strongly buffered than the Java part (that is, the C++ stuff stays in memory longer before being written to the disk).



-chris
About | Sitemap | Contact