tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jacob Kjome <h...@visi.com>
Subject Re: Tomcat 5.5.4 and Log4j
Date Wed, 24 Nov 2004 16:13:04 GMT

Look in the archives for another email from me.  The fact is that the logger
naming scheme used by Tomcat for its host and context logs is simply
incompatible with the DOMConfigurator.  This is because the XML files it
processes use the log4j.dtd which define the <logger> "name" attribute as an
ID.   The problem occurrs with the characters "[", "]", and "/".  See the XML
spec (or my other email somewhere in the archives of Tomcat-user or log4j-user)
for details on legal characters for attributes of type ID.

There is hope coming in Log4j-1.3 which deprecates the DOMConfigurator in favor
of the JoranConfigurator which works with more free-form xml (not enforced by
DTD) configuration files.

However, your immediate solution is to use a log4j.properties file to configure
Tomcat-5.5.x logging.  Here's an example...


log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%-5p[%-8.8t]: %39.39c %-6r - %m%n

log4j.appender.A2=org.apache.log4j.FileAppender
log4j.appender.A2.File=${catalina.home}/logs/stdout.log
log4j.appender.A2.Append=false
log4j.appender.A2.layout=org.apache.log4j.PatternLayout
log4j.appender.A2.layout.ConversionPattern=%-5p[%-8.8t]: %39.39c %-6r - %m%n

log4j.appender.LOCALHOST=org.apache.log4j.RollingFileAppender
log4j.appender.LOCALHOST.File=${catalina.home}/logs/localhost.log
log4j.appender.LOCALHOST.MaxFileSize=1000KB
log4j.appender.LOCALHOST.MaxBackupIndex=1
log4j.appender.LOCALHOST.layout=org.apache.log4j.PatternLayout
log4j.appender.LOCALHOST.layout.ConversionPattern=%-5p[%-8.8t]: %39.39c %-6r -
%m%n

log4j.appender.CONTEXT1=org.apache.log4j.DailyRollingFileAppender
log4j.appender.CONTEXT1.File=${catalina.home}/logs/localhost_context1.log
log4j.appender.CONTEXT1.DatePattern='.'yyyy-MM-dd
log4j.appender.CONTEXT1.layout=org.apache.log4j.PatternLayout
log4j.appender.CONTEXT1.layout.ConversionPattern=%c{1} %-6r - %m%n

log4j.appender.CONTEXT2=org.apache.log4j.DailyRollingFileAppender
log4j.appender.CONTEXT2.File=${catalina.home}/logs/localhost_context2.log
log4j.appender.CONTEXT2.DatePattern='.'yyyy-MM-dd
log4j.appender.CONTEXT2.layout=org.apache.log4j.PatternLayout
log4j.appender.CONTEXT2.layout.ConversionPattern=%c{1} %-6r - %m%n

log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/context1]=INFO,
CONTEXT1
log4j.additivity.org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/context1]=false

log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/conext2]=INFO,
CONTEXT2
log4j.additivity.org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/context2]=false

log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost]=INHERIT,
LOCALHOST
log4j.additivity.org.apache.catalina.core.ContainerBase.[Catalina].[localhost]=false

log4j.rootLogger=INFO, A1



Jake

Quoting Wouter De Vaal <wouterv@gmail.com>:

> Hi,
>
> I'm having difficulties to configure log4j with tomcat logging per context.
> Here's what I have done:
> 1. I've added log4j.jar to the bin dir
> 2. I've created a log4j.xml in common/classes and added the log4j.dtd
> This seems to work, because when I add a debug logger for org.apache,
> I get a lot of extra logging lines in stdout.log.
> But now I have a new webapp called "advertisements" and this is de
> message that I get in de stdout.log:
> log4j:WARN No appenders could be found for logger
>
(org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/advertisements]).
> log4j:WARN Please initialize the log4j system properly.
>
> But when I add the logger with this name I get the following error:
> log4j:ERROR Parsing error on line 10 and column 100
> log4j:ERROR Attribute value
>
"org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/advertisements]"
> of type ID must be a name.
>
> So I guess log4j can't handle these names?
>
> I've also tried to use a log4j.properties (which also works when I add
> a debug logger for org.apache), but that doesn't work either, but this
> time I only get the first warning.
>
> My log4j.xml:
> <?xml version="1.0" encoding="UTF-8" ?>
> <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
> <log4j:configuration>
>    <!-- STDOUT: Outputs log information to the standard output/console -->
>    <appender name="STDOUT" class="org.apache.log4j.ConsoleAppender">
>        <layout class="org.apache.log4j.PatternLayout">
>            <param name="ConversionPattern" value="%d %-5p - %m%n"/>
>        </layout>
>    </appender>
>    <logger
>
name="org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/advertisements]">
>        <level value="DEBUG"/>
>        <appender-ref ref="STDOUT"/>
>    </logger>
>    <logger name="org.apache">
>        <level value="INFO"/>
>        <appender-ref ref="STDOUT"/>
>    </logger>
>    <root>
>        <level value="ERROR"/>
>    </root>
> </log4j:configuration>
>
> alternative log4j.properties:
> log4j.rootLogger=ERROR, A1
> log4j.appender.A1=org.apache.log4j.ConsoleAppender
> log4j.appender.A1.layout=org.apache.log4j.PatternLayout
>
> # Print the date in ISO 8601 format
> log4j.appender.A1.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
>
> #log4j.logger.org.apache=DEBUG,A1
>
log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/advertisements]=INFO,A1
>
> Regards,
> Wouter de Vaal
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>




---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message