tags:

views:

405

answers:

3

I have made a java application and wants to generate log files so whenever my client would encounter some problem, he can deliver me those log files so that I can correct my code accordingly.

  1. Kindly provide me a small sample program that writes a statement to a log file. Kindly mention the .class files you are using with their full import statements.

  2. The application is multi-threaded so Is it better to generate separate log files for each thread or not?

  3. Is it better to clear all previous log files before starting the program?

+3  A: 

Apache Log4j does everything you require. I hope that you can figure out how to use it on your own.

mikek
+3  A: 

Take a look at Log4j, and specifically this set of step-by-step examples. It's pretty trivial.

Brian Agnew
+4  A: 

macleojw is correct: You should try writing the code yourself.

Here is an overview of the Java logging framework that ships with the JDK. You may wish to check out Commons Logging and Log4J.

Regarding the second part of your question (which was editted out for some reason) I would recommend having all threads log to the same file but logging the thread name along with the log message allowing you to grep the file for a specific thread if required. Also, with most logging frameworks you can configure them to maintain a rolling window of the last N log files rather than explicitly deleting old files when an application starts.

Adamski