I'd like to know if I'm correctly using log4j to check the integriity of my DAO classes in a JSP MVC user admin application. I included the log4j jar file in my library and added the following files and code. The problem is that I do not see any output to the console apart from the usual Tomcat logs and Netbeans. I even modified the SQL query so that it causes a SQL exception and invokes the log4j but i still do not see any console output. Any help is much appreciated. The code is as follows:
If you're asking about Tomcat, then what is the "console" you're looking at. As far as I know Tomcat intercepts everything written to System.out and writes it to some log file somewhere instead, but people in the Tomcat forum would no doubt have better answers. So let's move this post there.
I'm fine to move it there although I think I've resolved the problem. I'm looking at the Tomcat console in Netbeans 7.3.1 and log4j prints within the console. The problem is Netbeans keeps the prior Tomcat log unless you clear the log files before re-deploying the application so I was not able to read the log4j output. I now confirmed that it is there. Thanks for your help!
The log4j console appender writes to the JVM's stdout.
However, the concepts of stdout and stderr don't really exist in a J2EE environment, so there's no telling where the output may go - including into a black hole. So for critical logging information, it's better to log to a more concrete channel, such as a specific log file, network pipe, email, or whatever.
In the vanilla version of Tomcat, the JVM's stdout and stderr is directed into a file named TOMCAT_HOME/logs/catalina.out. However, some Windows spins of Tomcat may open a console window instead or lose the data entirely. When using an IDE to run Tomcat, the IDE J2EE plugin often intercepts the console and may or may not replicate it into a log file.
Some people, when well-known sources tell them that fire will burn them, don't put their hands in the fire.
Some people, being skeptical, will put their hands in the fire, get burned, and learn not to put their hands in the fire.
And some people, believing that they know better than well-known sources, will claim it's a lie, put their hands in the fire, and continue to scream it's a lie even as their hands burn down to charred stumps.
Thanks a lot for this useful advice. I did notice in Netbeans that the log4j output to the console seems to result in a mish mash between the Netbeans, Tomcat and log4j loggers. From your advice I figured the best option is to output to a file, using the following log4j.properties file:
CAUTION! Do not touch the blades on your neck propeller while they are active. Tiny ad: