Link to home
Start Free TrialLog in
Avatar of Angela123
Angela123

asked on

Adding log4J to a JSP

I have been asked to add log4J to a JSP so I can test application logging. Im not sure where to begin and what to put in the jsp?

any help would be appreciated.
ASKER CERTIFIED SOLUTION
Avatar of mrcoffee365
mrcoffee365
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I agree with the above except for the part about manually configuring log4j using PropertyConfigurator. For one thing, the pattern above is going to reconfigure log4j every time you hit the page. I always like to leverage log4j's automatic configuration by putting the configuration file (and I prefer the XML form) somewhere on the classpath so that log4j can find it and configure itself when necessary. If you prefer a more JSP-ish way of logging, have a look at http://jakarta.apache.org/taglibs/doc/log-doc/intro.html.

Regards,
Jim Cakalic
If you are going to use taglibs, then this site has a very nice walk-through of how to use log4j tags in a JSP page:
http://www.mobilefish.com/developer/log4j/log4j_quickguide_jsp.html

However, if you don't use taglibs, it's easier to set up a more basic configuration as I documented above.