Reputation: 959
I wrote a complex application and now i have to debug it with the help of some testers. The problem i'm now facing is that they cannot know what kind of exception occurred during the use of the software. Is there a fast way to get the Console stream and show it's messages in another window while the user is using an Application or an Applet?
Upvotes: 0
Views: 100
Reputation: 7207
You can redirect all console messages to file (or other stream) on application start, and then look file content for get Exception:
FileOutputStream fos = new FileOutputStream("log.txt");
PrintStream out = new PrintStream(fos);
System.setOut(out);
System.setErr(out);
System.out.println("Logged to file");
Upvotes: 1
Reputation: 328624
Use a logging framework like slf4j together with logback. It offers dozens of different "appenders" - helpers which save the log messages in various places.
For your use case, I suggest to write a new appender that collects the last 100 messages in a thread safe list.
Attach it to the root logger (see the documentation).
When an error or an exception is being logged, take all messages from the list and convert them into Strings. When using logback
, create an encoder for this.
Join the strings and display them in an text editor widget so clients can easily cut&paste the message into an email.
Alternatively, you can try the existing mail appender. Configure it to respond only to errors and have it send the error directly to you. But I suggest to make sure your mail provider can handle this - we had a case where a bug in the software caused sending of over 70'000 mails over night. After that, we learned that Outlook can't handle so many mails.
Upvotes: 1