我已将 Tomcat server.xml 配置为具有多个连接器:
<Service name="Catalina">
<Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol" SSLEnabled="true"
maxThreads="150" scheme="https" secure="true"
keystoreFile="C:\somekey.keystore" keystorePass="mykeypass"
clientAuth="false" sslProtocol="TLSv1" />
<Engine name="Catalina" defaultHost="localhost">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="access_log." suffix=".txt" pattern='%h %l %u %t "%r" %s %b %p %D %S' resolveHosts="false"/>
</Host>
</Engine>
<Engine name="CatalinaA" defaultHost="localhost">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
<Host name="localhost" appBase="webappsA"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logsA"
prefix="access_log_A." suffix=".txt" pattern='%h %l %u %t "%r" %s %b %p %D %S' resolveHosts="false"/>
</Host>
</Engine>
我还部署了两个 Web 应用程序,一个在 webapps (APPP1) 中,另一个在 webappsA (APPP2) 中。
这是我的 logging.properties:
handlers = 2APPP1.org.apache.juli.FileHandler, 3APPP2.org.apache.juli.FileHandler
.handlers = 2APPP1.org.apache.juli.FileHandler, 3APPP2.org.apache.juli.FileHandler
2APPP1.org.apache.juli.FileHandler.level = FINEST
2APPP1.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
2APPP1.org.apache.juli.FileHandler.prefix = APPP1.
3APPP2.org.apache.juli.FileHandler.level = FINEST
3APPP2.org.apache.juli.FileHandler.directory = ${catalina.base}/logsA
3APPP2.org.apache.juli.FileHandler.prefix = APPP2.
java.util.logging.ConsoleHandler.level = ALL
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
############################################################
# Facility specific properties.
# Provides extra control for each logger.
############################################################
org.apache.catalina.core.ContainerBase.[Catalina].[/APPP1].level = INFO
org.apache.catalina.core.ContainerBase.[CatalinaA].[/APPP2].level = INFO
org.apache.catalina.core.ContainerBase.[Catalina].[/APPP1].handlers = 2APPP1.org.apache.juli.FileHandler
org.apache.catalina.core.ContainerBase.[CatalinaA].[/APPP2].handlers = 3APPP2.org.apache.juli.FileHandler
org.apache.catalina.level = WARNING
日志被分开到不同的文件夹,两个应用程序的访问日志都可以,但是 Tomcat 日志将每个应用程序请求都记录到 APPP1.log 和 APPP2.log 文件中。