Igor Vuković
Igor Vuković

Reputation: 763

Apache Tomcat logging multiple services for multiple applications

I have configured a Tomcat server.xml to have multiple connectors:

   <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>

I have also deployed two web applications, one in webapps (APPP1) and another in webappsA (APPP2).
Here are my 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

The logs are separated to different folders, the access log is ok for both apps, but the Tomcat log is logging every application request both to APPP1.log and APPP2.log file.

Upvotes: 0

Views: 3034

Answers (3)

nweiler
nweiler

Reputation: 1190

By including the line:

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

you are assigning both of these file handlers to the root logger. The file associated with each of these file handlers is getting the output from the default logger (i.e. all output).

Upvotes: 1

Igor Vuković
Igor Vuković

Reputation: 763

I put logging.properties into WEB-INF/classes of every app, and deleted logging.properties from the ApacheTomcat/conf/ directory and everything works like a charm.

Upvotes: 0

Christopher Schultz
Christopher Schultz

Reputation: 20862

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

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

You have your loggers registered twice, so they get called twice. Try only registering them once.

Upvotes: 0

Related Questions