所以有一种方法可以通过 $TOMCAT_HOME/conf/logging.properties 而不用接触我的 servlet 代码......
前...
handlers = 1catalina.org.apache.juli.FileHandler, 2localhost.org.apache.juli.FileHandler, 3manager.org.apache.juli.FileHandler, 4admin.org.apache.juli.FileHandler, 5host-manager.org.apache.juli.FileHandler, java.util.logging.ConsoleHandler
后...
handlers = 1catalina.org.apache.juli.FileHandler, 2localhost.org.apache.juli.FileHandler, 3manager.org.apache.juli.FileHandler, 4admin.org.apache.juli.FileHandler, 5host-manager.org.apache.juli.FileHandler, java.util.logging.ConsoleHandler, 6localhost.org.apache.juli.FileHandler
然后加...
6localhost.org.apache.juli.FileHandler.level = FINE
6localhost.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
6localhost.org.apache.juli.FileHandler.prefix = myAppName.
并添加...
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/myAppName].level = INFO
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/myAppName].handlers = 6localhost.org.apache.juli.FileHandler
和反弹tomcat。这仅使用我简单的 ServletConfig.getServletContext().log() 消息创建了 $TOMCAT_HOME/logs/myAppName.2008-10-14.log。