0
votes

I have followed the directions to configure tomcat 6 to log using log4j from here: Logging in Tomcat

However, I have noticed that threads appear to be logging to stdout, with no regard to the log level set in log4j.properties. Here is my log4j.properties file:

    log4j.rootLogger=WARN, CATALINA
    # Define all the appenders
    log4j.appender.CATALINA=org.apache.log4j.DailyRollingFileAppender
    log4j.appender.CATALINA.file=${catalina.base}/logs/tomcat.out
    log4j.appender.CATALINA.encoding=UTF-8
    # Roll-over the log once per day
    log4j.appender.CATALINA.DatePattern='.'yyyy-MM-dd'.log'
    log4j.appender.CATALINA.layout.ConversionPattern = %d [%t] %-5p %c- %m%n
    log4j.appender.CATALINA.layout=org.apache.log4j.PatternLayout
    log4j.appender.CATALINA.append=true

    log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
    log4j.appender.CONSOLE.encoding=UTF-8
    log4j.appender.CONSOLE.conversionPattern = %d [%t] %-5p %c- %m%n

    # Configure which loggers log to which appenders
    #log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost]=INFO, LOCALHOST
    #log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager]=INFO, MANAGER
    #log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager]=INFO, HOST-MANAGER

    log4j.logger.org.hibernate.hql.ast=ERROR

This is the file that's in my ${CATALINA_BASE}/lib directory. Notice the last line where I set org.hibernate.hql.ast level to ERROR. The following is constantly being spewed into my tomcat.out log:

15663118 [http-8080-1] WARN org.hibernate.hql.ast.QueryTranslatorImpl - firstResult/maxResults specified with collection fetch; applying in memory!
15663531 [TP-Processor7] WARN org.hibernate.hql.ast.QueryTranslatorImpl - firstResult/maxResults specified with collection fetch; applying in memor
62100 [http-8080-18] INFO org.hibernate.cache.StandardQueryCache - starting query cache at region: video

I have a similar log4j.properties file deployed in my webapp under WEB-INF/classes that have similar properties (but logs to a different file). How come the log statements do not follow the conversion pattern I have defined, nor follow the log level limit I set?

I'm running tomcat 6.0.30, Java 1.6.0_23, and log4j 1.2.16 on SunOS 5.10 amd64. The output to my application log works as expected. Thanks in advance for your help.

Andrew

1

1 Answers

0
votes

The main problem here is that you're using the old properties file -style way of configuring Log4J. Because most people use XML configuration method these days, you'll be hard pressed to find anyone who can answer the question.

However, what you need to do is to set threshold for each appender. This is how it's done in XML:

   <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
   ...
      <param name="Target" value="System.out"/>
      <param name="Threshold" value="WARN"/>

   ...
   </appender>

It might look like his on flat file:

log4j.appender.Console.Threshold=WARN