0

我已将 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 文件中。

4

3 回答 3

1

通过包括以下行:

.handlers = 2APPP1.org.apache.juli.FileHandler, 3APPP2.org.apache.juli.FileHandler

您正在将这两个文件处理程序分配给根记录器。与这些文件处理程序中的每一个关联的文件正在从默认记录器获取输出(即所有输出)。

于 2013-08-14T21:16:41.987 回答
0

我将 logging.properties 放入每个应用程序的 WEB-INF/classes 中,并从 ApacheTomcat/conf/ 目录中删除了 logging.properties,一切都很顺利。

于 2012-07-15T07:54:19.607 回答
0

处理程序 = 2APPP1.org.apache.juli.FileHandler,3APPP2.org.apache.juli.FileHandler

.handlers = 2APPP1.org.apache.juli.FileHandler, 3APPP2.org.apache.juli.FileHandler

你的记录器注册了两次,所以他们被调用了两次。尝试只注册一次。

于 2012-07-13T13:44:52.857 回答