Win a copy of Programming with Types this week in the Angular and TypeScript forum
or The Design of Web APIs in the Web Services forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Henry Wong
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Joe Ess
  • salvin francis

Using log4j in a JSP MVC app

 
Ranch Hand
Posts: 222
Netbeans IDE MySQL Database Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:

log4j.properties



 
Marshal
Posts: 24843
60
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jay Tai
Ranch Hand
Posts: 222
Netbeans IDE MySQL Database Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Saloon Keeper
Posts: 21446
143
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Jay Tai
Ranch Hand
Posts: 222
Netbeans IDE MySQL Database Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim,

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:


 
no wonder he is so sad, he hasn't seen this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!