Search This Blog

Friday, March 4, 2011

Using Apache's log4j library - how to?


  • 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:
  1. http://www.laliluna.de/articles/log4j-tutorial.html
  2. http://logging.apache.org/log4j/1.2/download.html
  3. http://en.wikipedia.org/wiki/Log4j

    No comments:

    Post a Comment