简体   繁体   中英

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 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 (ie 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.

Tomcat文档中有一章介绍如何配置服务器的日志记录属性: 登录Tomcat

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM