log4j.properties vs. log4j.xml


General J2EE: log4j.properties vs. log4j.xml

  1. log4j.properties vs. log4j.xml (4 messages)

    i have a log4j.properties file that logs my struts application.

    my root level is info, and i set the level for org.apache.struts to warn (this supresses all info logs from struts).

    log4j.rootLogger=info, R
    log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n

    now i am trying to have the same behaviour using log4j.xml:
    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

    <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">

    <!-- Ausgabe in eine Datei -->
    <appender name="datei"
    <!-- <param name="Threshold" value="INFO" /> -->
    <param name="File" value="kiqn.log" />
    <param name="Append" value="true" />
    <param name="MaxFileSize" value="100KB" />
    <param name="MaxBackupIndex" value="1" />
    <layout class="org.apache.log4j.PatternLayout">
    <param name="ConversionPattern" value="%d %-5p [%c] %m%n" />
    <logger name="org.apache.struts">
            <level value="info"/>
            <appender-ref ref="datei"/>
         <level value="info" />
         <appender-ref ref="datei" />

    I expected this xml file the behave like the properties file, but it doesnt. i get a lot of info logs from org.apache.struts.

    Can somebody help ?

    Threaded Messages (4)

  2. log4j.properties vs. log4j.xml[ Go to top ]

    Well, it seems that you assigned the INFO level to your org.apache.struts logger in your XML configuration file, instead of the WARN level that was assigned to it in your properties file. I think it can explain why you have INFO logs now.
  3. log4j.properties vs. log4j.xml[ Go to top ]

    sorry, i made a mistake when posting. the level of org.apache.struts is of course "warn" in both files.

    still i get infos from struts in the xml version.
  4. Problem with Log4j.xml[ Go to top ]

    Same here. The root logger seems to over-ride the application log level:

    <logger name="com.xyz.abc.logger.MyLogger">
    <level value="error"/>
                    <appender-ref ref="MyAppender"/>

    <!-- Configure the root appender -->
                    <priority value="debug" />
                    <appender-ref ref="stdout"/>
                    <appender-ref ref="MyAppender"/>

    I still get DEBUG messages from MyLogger in MyAppender.

    Any help, anyone???? It seems to be a bug in log4j1.2.7.

    I have seen this working for log4j1.3-alpha.

    Any pointers would be appreciated.

  5. Set additivity="false"[ Go to top ]

    For each level that you wish to "override" a parent (in this case the root level). You need to set the attribute additivity="false" to the logger element. This will give you the desired results.