log4j 2 used with Payara 4 does not create logs
I’m currently trying to use log4j 2 within an .ear that gets deployed in a Payara application server version 4.1.2. My problem is that nothing gets logged, neither in the console nor in a logfile. The logfile "app.log" I defined in the log4j2.xml doesn’t exist anywhere on my machine after calling the REST endpoint where I use log4j2. Does anyone have a clue what could be the problem?
Entries in my pom:
<dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-api</artifactId> <version>2.13.3</version> </dependency> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-core</artifactId> <version>2.13.3</version> </dependency>
my log4j2.xml located in src/main/resources:
<?xml version="1.0" encoding="UTF-8"?> <Configuration status="WARN"> <Appenders> <Console name="Console" target="SYSTEM_OUT"> <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/> </Console> <File name="LogToFile" fileName="logs/app.log"> <PatternLayout> <Pattern>%d %p %c{1.} [%t] %m%n</Pattern> </PatternLayout> </File> </Appenders> <Loggers> <Logger name="package.package" level="info" additivity="false"> <AppenderRef ref="LogToFile"/> </Logger> <Root level="error"> <AppenderRef ref="Console"/> <AppenderRef ref="LogToFile"/> </Root> </Loggers> </Configuration>
I’m using log4j 2 like the following as it’s described in many instructions online. It’s used inside a REST controller, but I removed the irrelevant parts of the code.
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; public class App { public static final Logger LOGGER = LogManager.getLogger(App.class); public Response start() { LOGGER.info("START PROCESS"); ... LOGGER.info("PROCESS FINISHED"); return Response.status(...).entity(...).build(); } }
When doing my research I found the following thread: https://stackoverflow.com/a/61676705/12755770 But it’s about Payara 5. I created the system property fish.payara.classloading.delegate=false anyway but without success.