Logging to Log File Stopped With Java 11

161 Views Asked by At

I am migrating a java application which was compiled using Java 8 and deployed in Wildfly 10 application server. This application deploys and runs successfully.

The logging in the application uses log4j2 configuration and the logging is configured to write to a log file specified in the RollingFileAppender.

All the logging works fine ie can set different LOG LEVELS, define different Loggers to control logging at package level etc.

So all fine with Java 8 and with the application running in Wildfly 10.

The application is than compiled with Java 11 and deployed in Wildfly 15 and again deploys and runs successfully.

However, the logging to the log file has stopped working with Java 11.

The application creates the log file as before and there are no errors reported. Changing the LOG LEVELS in the log4j2 file makes no difference. In the move to build with Java 11 and to use WIldfly 15, there are no chnages to the dependencies or to the log4j2 configuration file.

Not able to share actual code but below is a good refection of the log4j2.xml and source code.

log4j2.xml

<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
    <Appenders>
        <Console name="Console" target="SYSTEM_OUT">
            <PatternLayout pattern="%d{HH:mm:ss.SSS} %-5level - %msg%n"/>
        </Console>
        
        <!-- Complete definiton not provided RollingFile -->
        <RollingFile name="File" fileName="/tmp/log4j2.log" >
            <PatternLayout>
                <Pattern>%d{HH:mm:ss.SSS} [%t] %-5level - %msg%n</Pattern>
            </PatternLayout>
        </RollingFile>
    </Appenders>
    <Loggers>
        <Logger name="com.sematext.blog" level="info" additivity="true">
            <AppenderRef ref="Console"/>
        </Logger>
        <Root level="info">
            <AppenderRef ref="File"/>
        </Root>
    </Loggers>
</Configuration>

Similar source code

    package com.sematext.blog.logging;

    import org.apache.logging.log4j.LogManager;
    import org.apache.logging.log4j.Logger;

    public class Log4JDefaultConfig {
            
            private static final Logger LOGGER = LogManager.getLogger(Log4JDefaultConfig.class);

            public  void processMessage () { 
                LOGGER.info("This is an INFO level log message!");
                LOGGER.debug("This is an DEBUG level log message!");
                LOGGER.error("This is an ERROR level log message!");
        }
    }

I am able debug through the processMessage() method and still nothing gets logged to the log file.

Under Eclipse, I use the facility to open declaration of method for info(), debug() and error().

They all take me to log4j-api-2.17.1.jar

I have also added the following to the application build.gradle file this made no difference. This is a suggestion I picked up from googling this issue.

jar {
    manifest {
        attributes 'Multi-Release': 'true'
    }
}

Any thoughts as to why logging to the log file has stopped please.

Thank you for all the help

Pete

1

There are 1 best solutions below

1
On

Is logging part of your application or the container?

Wildfly 10 most likely contained a log4j 1 implementation, whereas newer versions of Wildfly come with log4j 2 installed. If you do not notice, your application might assume that log4j2 (what you see as being used) is it's private installation while in newer JBoss you'd now have to decide which of the two log4j 2 implementations is getting configured and used.