0

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

Pete Long
  • 107
  • 2
  • 11
  • without more server details; I'd be leaning towards the security context of execution preventing you from writing to /tmp; however you haven't given enough details of how you're running to determine what the issue might be. I'd be firing up strace, or something like that to see if there is even an attempt to open up the log file – Anya Shenanigans Aug 16 '23 at 21:14
  • WildFly 15 is still rather old, however it doesn't ship with a log4j2 implementation. Are you including both the log4j 2 API and core libraries? – James R. Perkins Aug 17 '23 at 00:05

1 Answers1

0

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.

Queeg
  • 7,748
  • 1
  • 16
  • 42
  • The logging is part of the application. How can I determine whether the private ( existing ) or the JBoss log4j 2 implementation is used and how can set such that the private log4j2 is used please. – Pete Long Aug 17 '23 at 07:37