first_page the funky knowledge base
personal notes from way, _way_ back and maybe today

“How to Use Log4J within eclipse in 10 Minutes”; http://snippets.dzone.com/posts/show/3248

  1. Download log4j http://logging.apache.org/site/binindex.cgi

  2. Unpack the .zip file in your Java folder (In Windows it is usually C:\\Program Files\\Java\\)

  3. In Eclipse: Window > Preferences… > Java > Build Path > User Libraries > New: "log4j" > OK Add JARs… > navigate to find your log4j .jar you just unpacked in the Java Folder > OK

  4. Right click on your project in the Package Explorer > New > Folder In “Folder name” write "log4j", click Advanced. Select “Link to a folder in the file system” Create a new folder "log4j" in your project folder in the file system.

  5. Place this file you are reading right now in in the folder you just created. Name the file as log4j.properties

  6. In Eclipse: Run > Run… In the navigation bar on the left select either the server, or the runnable class, or the JUnit test you want to log with log4j

Select the Classpath tab > User Entries > Advanced… > Add folders > OK

Select the "log4j" folder you created in your project and click OK

  1. Repeat step 6 for other servers, runnable classes or JUnit tests you want to log

  2. Change in the following line the "org.example.foo.bar" with whatever you want:

    log4j.category.org.example.foo.bar=DEBUG

  3. Add the following import to the Java Class you want to log: import org.apache.log4j.Logger;

  4. Add this lines to the Java Class you want to log:

    /**

    • Log4j logger */ static Logger log4j = Logger.getLogger("org.example.foo.bar");
  5. Substitute in the code above "org.example.foo.bar" with whatever your wrote in the step 8.

  6. Add something like the following code in your Class whenever you want to log:

    log4j.debug("WTF?");

  7. Repeat steps 9, 10, 11 and 12 for every Java Class you want to log

  8. Enjoy!

mod date: 2007-12-28T18:52:08.000Z