简体   繁体   中英

Why are the non-root level loggers not receiving logging?

I am in the process of migrating an application from Log4J 1.2.16 to Log4J 2.13.3. I am using the Log4J2 1.2 to 2.13.3 bridge for this purpose. On my own development machine everything is working perfectly. However, when I deploy the application to a test server the logging gets send to the root logger only, the other log files I have defined stay empty.

The log4j2.xml configuration files on both machines are exactly the same, only the paths in the appenders differ. My development machine runs Windows, the test server runs Linux. The application is deployed to Weblogic 12.2.1.3.

I have included the log4j2.xml file on the test server below (please excuse the messy replace statement). To be clear: all logging gets send to ERROR_LOG (as that is the one referenced in the root logger), the other three logfiles are created but stay empty on the test server, while they do receive data on my development machine.

<?xml version="1.0" encoding="UTF-8" ?>
<Configuration monitorInterval="60">
    <Appenders>
        <RollingFile name="ERROR_LOG" fileName="/var/log/weblogic/app/error.log" filePattern="/var/log/weblogic/app/error.log%d{yyyy-MM-dd}.gz">
            <PatternLayout charset="UTF-8" pattern="###%d{yyyy-MM-dd HH:mm:ss,SSS Z}{Europe/Amsterdam}|%d{yyyy-MM-dd HH:mm:ss,SSS Z}{UTC}|%-5p|%t|%c{2}|%replace{%replace{%replace{%m}{(&lt;[^/]*?[wW]achtwoord.*?&gt;).*?(&lt;/.*?[wWWachtwoord].*?&gt;)}{$1********$2}}{(&lt;pw&gt;).*?(&lt;/pw&gt;)}{$1********$2}}{(&lt;newPW&gt;).*?(&lt;/newPW&gt;)}{$1********$2}|%n" />
            <Policies>
                <TimeBasedTriggeringPolicy interval="1"/>
            </Policies>
            <DefaultRolloverStrategy max="7"/>
        </RollingFile>
        <RollingFile name="DEBUG_LOG" fileName="/var/log/weblogic/app/debug.log" filePattern="/var/log/weblogic/app/debug.log%d{yyyy-MM-dd}.gz">
            <PatternLayout charset="UTF-8" pattern="###%d{yyyy-MM-dd HH:mm:ss,SSS Z}{Europe/Amsterdam}|%d{yyyy-MM-dd HH:mm:ss,SSS Z}{UTC}|%-5p|%t|%c{2}|%replace{%replace{%replace{%m}{(&lt;[^/]*?[pP]assword.*?&gt;).*?(&lt;/.*?[pPPassword].*?&gt;)}{$1********$2}}{(&lt;pw&gt;).*?(&lt;/pw&gt;)}{$1********$2}}{(&lt;newPW&gt;).*?(&lt;/newPW&gt;)}{$1********$2}|%n" />
            <Policies>
                <TimeBasedTriggeringPolicy interval="1"/>
            </Policies>
            <DefaultRolloverStrategy max="7"/>
        </RollingFile>
        <RollingFile name="FACADE_LOG" fileName="/var/log/weblogic/app/facade.log" filePattern="/var/log/weblogic/app/facade.log%d{yyyy-MM-dd}.gz">
            <PatternLayout charset="UTF-8" pattern="###%d{yyyy-MM-dd HH:mm:ss,SSS Z}{Europe/Amsterdam}|%d{yyyy-MM-dd HH:mm:ss,SSS Z}{UTC}|%-5p|%t|%c{2}|%replace{%replace{%replace{%m}{(&lt;[^/]*?[pP]assword.*?&gt;).*?(&lt;/.*?[pPPassword].*?&gt;)}{$1********$2}}{(&lt;pw&gt;).*?(&lt;/pw&gt;)}{$1********$2}}{(&lt;newPW&gt;).*?(&lt;/newPW&gt;)}{$1********$2}|%n" />
            <Policies>
                <TimeBasedTriggeringPolicy interval="1"/>
            </Policies>
            <DefaultRolloverStrategy max="7"/>
        </RollingFile>
        <RollingFile name="AUDIT_LOG" fileName="/var/log/weblogic/audit/audit.log" filePattern="/var/log/weblogic/audit/audit.log%d{yyyy-MM-dd}.gz">
            <PatternLayout charset="UTF-8" pattern="###%d{yyyy-MM-dd HH:mm:ss,SSS Z}{Europe/Amsterdam}|%d{yyyy-MM-dd HH:mm:ss,SSS Z}{UTC}|%-5p|%t|%c{2}|%replace{%replace{%replace{%m}{(&lt;[^/]*?[pP]assword.*?&gt;).*?(&lt;/.*?[pPPasword].*?&gt;)}{$1********$2}}{(&lt;pw&gt;).*?(&lt;/pw&gt;)}{$1********$2}}{(&lt;newPW&gt;).*?(&lt;/newPW&gt;)}{$1********$2}|%n" />
            <Policies>
                <TimeBasedTriggeringPolicy interval="1"/>
            </Policies>
            <DefaultRolloverStrategy max="7"/>
        </RollingFile>
    </Appenders>
    <Loggers>
        <Logger name="nl.test.app.facade" level="debug" additivity="false">
            <AppenderRef ref="FACADE_LOG"/>
        </Logger>
        <Logger name="nl.test.app.auditadapter" level="debug" additivity="false">
            <AppenderRef ref="AUDIT_LOG"/>
        </Logger>
        <Logger name="nl.test.app.proces" level="debug" additivity="false">
            <AppenderRef ref="DEBUG_LOG"/>
        </Logger>
        <Root level="debug">
            <AppenderRef ref="ERROR_LOG" />
        </Root>
    </Loggers>
</Configuration>

On my own machine I added the location of the log4j2.xml to the classpath. On the test server I have tried adding the location to the classpath as well as setting it through the log4j.configurationFile Java VM parameter. The result in both cases is the same: all the logfiles are created at startup but only the one mentioned in the root logger (ERROR_LOG) gets logdata send to it, the other logfiles stay empty. This tells me that at least Log4J2 is able to find and read the configuration file. I have tried switching the appender which is mentioned in the root logger. In that case logging data gets send to that file, so it does not seem to be anything filesystem related.

So the question is: why do the logfiles on my test server stay empty (except the one mentioned in the root logger) but receive data on my development machine?

In the end there was still a stray log4j 1.x JAR in the application artifact, after removing that everything worked fine. You would expect some errors or at least a clue in Log4J's debug logging but that wasn't the case. Then again, classpath problems (which I guess this is) can be tricky.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM