0

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.

Jonathan Spooner
  • 7,682
  • 2
  • 34
  • 41
Igor Vuković
  • 742
  • 12
  • 25

3 Answers3

1

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

nweiler
  • 1,140
  • 1
  • 13
  • 23
  • 1
    That totally explains the behaviour - the logs were being handled by the root `''` Logger (which emits to both handlers) and NOT by the 'per-webapp' loggers - they got skipped entirely. – David Bullock Oct 09 '13 at 02:30
0

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.

Christopher Schultz
  • 20,221
  • 9
  • 60
  • 77
  • Nope, the 'handlers' line declares the handlers and what to call them, and the '.handlers' line gives both of them to the root logger at `''`. Hope you have a JULI-free day, because it's making mine pretty ordinary. – David Bullock Oct 09 '13 at 02:37
0

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.

Rndm
  • 6,710
  • 7
  • 39
  • 58
Igor Vuković
  • 742
  • 12
  • 25
  • Where 'charm' means "I have to unpackage the WAR file and hack a file before it will work properly". However, I think you have found the only way. I [doubt](http://stackoverflow.com/questions/19261727/in-tomcat-juli-do-the-facility-specific-loggers-become-per-webapp-logger-root) it can actually be done the way you (quite reasonably, IMHO) expected it to work. – David Bullock Oct 09 '13 at 02:33
  • I have just packed my war with the logging.properties – Igor Vuković Aug 01 '16 at 14:38