How to use Java Logging API in Servlet Application with Maven
I'm using Java Logging API in a simple Servlet application that uses Maven and deploying it on Tomcat. I want write logs to files. Although I have put my logging.properties in both source\main\resources and source\main\webapp\WEB-INF, it seems that this file is not read. There is not output log file.
If I change file logging.properties in JRE lib, log files are created properly.
How can I use Java Logging API to write log to file without modifying logging.properties in JRE lib?
P/S: I have used log4j which seems very easy to me. I'm trying to use Java Logging API because I'm curious about why there are many people still use it, including GoogleApp Engine.
For newbie like me, below is summary开发者_如何学JAVA for the problem:
1. Put logging.properties under WEB-INF\classes, look at tomcat docs for a sample of this file 2. If app is deployed manually (i.e. put .war in Tomcat's webapps folder), it should work properly 3. If app is deployed from Netbeans, it should work properly 4. If app is deployed from Eclipse, add the following under the Arguments tab of its launch configuration -Dcatalina.base=%PATH_TO_TOMCAT_INSTALLATION% -Dcatalina.home=%PATH_TO_TOMCAT_INSTALLATION% -Djava.util.logging.config.file=%PATH_TO_TOMCAT_INSTALLATION%\conf\logging.properties" -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager It seems that Eclipse use its own way to launch Tomcat, not execute startup.bat.The Tomcat documentation has a chapter on how to configure logging properties for your server: Logging in Tomcat
精彩评论