Question

On my SpringMVC project I enabled email logging starting from INFO massage (default behaviour is starting from ERROR message).

This is my appender configuration in log4j.xml:

<appender name="SMTP" class="org.apache.log4j.net.SMTPAppender">
    <param name="SMTPDebug" value="true"/>
    <param name="SMTPProtocol" value="smtps"/>
    <param name="SMTPUsername" value="*"/>
    <param name="SMTPPassword" value="*"/>
    <param name="SMTPHost" value="*"/>
    <param name="SMTPPort" value="*"/>
    <param name="Subject" value="*"/>
    <param name="To" value="*"/>
    <param name="From" value="*"/>
    <param name="BufferSize" value="5"/>
    <layout class="org.apache.log4j.PatternLayout">
        <param name="ConversionPattern" value="%d{MM/dd/yyyy HH:mm:ss} [%M] %-5p %C - %m%n" />
    </layout>
    <triggeringPolicy  class="org.apache.log4j.rolling.FilterBasedTriggeringPolicy">
      <filter class="org.apache.log4j.filter.LevelRangeFilter">
        <param name="levelMin" value="INFO" />
      </filter>
    </triggeringPolicy>
</appender>

It works on runtime but I get the same xml parser error and warning launching the project:

log4j:WARN The content of element type "appender" must match "(errorHandler?,param,rollingPolicy?,triggeringPolicy?,connectionSource?,layout?,filter*,appender-ref*)".*

What's wrong?
I'm using log4j-1.2.16.

Was it helpful?

Solution

I believe the reason to be that the order of the children in the XML <appender> element must follow the order declared in the DTD that the warning message shows. Quoting W3Schools about DTD elements:

When children are declared in a sequence separated by commas, the children must appear in the same sequence in the document.

Put your <layout> element after the <triggeringPolicy> element and the warning will likely disappear.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top