- Download the jar file from http://logging.apache.org/log4j/1.2/download.html.
- Include it in the classpath by referencing it in the project as shown below..
- Create a properties file "log4j.properties" (same as this file name) with following contents.
- Write a simple class like this..
- Wherever you create a new class just add the static member "logger" to your class, and start using it.
- Start writing the log statements.
- Collect all your log statements in your log file (as well as the console because of stdout in the properties file).
- Thats it!! Enjoy debugging complex interleaving scenarios between multiple threads. You can use Notepad++ for filtering and using such log files when they are too big to browse through.
References:
- http://www.laliluna.de/articles/log4j-tutorial.html
- http://logging.apache.org/log4j/1.2/download.html
- http://en.wikipedia.org/wiki/Log4j
No comments:
Post a Comment