logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Phillpotts, James" <james.phillpo...@logicacmg.com>
Subject Error when using system property in appender-ref element
Date Tue, 25 Sep 2007 13:49:44 GMT
Hi,

I'm using the ability for log4j to use system properties in order to
create a single log4j.xml that works on all types of environment
(development, test, production), with different levels of logging for
each environment. So I have something like:


    <appender name="testMyAppender"
class="com.foo.bar.tools.MyLogAppender">
        <!-- Need ConsoleAppender config, as MyLogAppender extends that
class 
             for use when logging is called outside BV container -->
        <param name ="Target" value="System.out"/>
        <param name ="Threshold" value="debug"/>
        
        <layout class="org.apache.log4j.PatternLayout">
            <!-- The default patter: Date Priority [Category] Message\n
-->
            <param name="ConversionPattern" value="%5p [%c{1}] - %m"/>
        </layout>
    </appender>
    
    <appender name="productionMyAppender"
class="com.foo.bar.tools.MyLogAppender">
        <!-- Need ConsoleAppender config, as MyLogAppender extends that
class 
             for use when logging is called outside BV container -->
        <param name ="Target" value="System.out"/>
        <param name ="Threshold" value="info"/>
        
        <layout class="org.apache.log4j.PatternLayout">
            <!-- The default patter: Date Priority [Category] Message\n
-->
            <param name="ConversionPattern" value="%5p [%c{1}] - %m"/>
        </layout>
    </appender>
    
    <logger name="com.foo.bar" additivity="false">
        <level value="debug"/>
        <appender-ref ref="${my.environment}MyAppender"/>
    </logger>


There is then a JVM parameter:
-Dmy.environment=<development|test|production>.

This works fine - log4j picks up the correct appender for the
environment, as seen in the debug below:


log4j: Threshold ="null".
log4j: Retreiving an instance of org.apache.log4j.Logger.
log4j: Setting [com.foo.bar] additivity to [false].
log4j: Level value for com.o2.dashboard is  [debug].
log4j: com.foo.bar level set to DEBUG
log4j: Class name: [com.foo.bar.tools.DashboardLogAppender]
log4j: Setting property [target] to [System.out].
log4j: Setting property [threshold] to [DEBUG].
log4j: Parsing layout of class: "org.apache.log4j.PatternLayout"
log4j: Setting property [conversionPattern] to [%5p [%c] - %m].
log4j: Adding appender named [testMyAppender] to category [com.foo.bar].
log4j: Setting property [additivity] to [false].
log4j: Level value for root is  [fatal].
log4j: root level set to FATAL
log4j: Adding appender named [thirdPartyAppender] to category [root].


However, before this logging I get two error messages:


log4j:ERROR Parsing error on line 186 and column 72
log4j:ERROR Attribute value "${my.environment}MyAppender" of type IDREF
must be a name.


It seems to me that this is a problem with the definition of the ref
attribute of the appender-ref element - the ref element has been defined
as IDREF, but IDREF doesn't allow the characters that I have used. Is
this an error in the dtd? Should the ref attribute actually be declared
as CDATA so that this sort of construct can be used without causing
errors every time the jvm starts?

Cheers,
James

PS - If it helps, I'm using log4j v 1.2.7.

    


This e-mail and any attachment is for authorised use by the intended recipient(s) only. It
may contain proprietary material, confidential information and/or be subject to legal privilege.
It should not be copied, disclosed to, retained or used by, any other party. If you are not
an intended recipient then please promptly delete this e-mail and any attachment and all copies
and inform the sender. Thank you.

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


Mime
View raw message