-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
  • 4
    Have a go at writing the code yourself and the come here if you've got a specific problem that you need help with.
    – macleojw
    Oct 23, 2009 at 8:28
  • 1
    I agree... this question doesn't help anyone, and you can get more examples than you can count on google. Oct 23, 2009 at 8:30
  • Is this votable for deletion?
    – OverLex
    Oct 23, 2009 at 8:35

3 Answers 3

4

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.

3

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

3

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.