javalog4j2weblogic14c

Weblogic 14.1.2.0.0 does not display logs in the console with log4j2


I’m using WebLogic 14.1.2.0.0 and trying to configure Log4j2 for logging in my application, but logs are not showing up in the console.

<dependency>
  <groupId>org.apache.logging.log4j</groupId>
  <artifactId>log4j-api</artifactId>
  <version>2.20.0</version>
</dependency>
<dependency>
  <groupId>org.apache.logging.log4j</groupId>
  <artifactId>log4j-core</artifactId>
  <version>2.20.0</version>
</dependency>

@Stateless
@GetTypeQualifierV2
public class GetTypeUserEvent implements EventTypeUserHandler {

    private static final Logger LOGGER = LogManager.getLogger(GetTypeUserEvent.class);

    @Override
    public void handle(Object event) {
        LOGGER.info("GetTypeUserEvent.handle() called with event: {}", event);
    }
}

/src/main/resources/log4j2.xml

<?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>
  </Appenders>
  <Loggers>
    <Root level="info">
      <AppenderRef ref="Console"/>
    </Root>
  </Loggers>
</Configuration>

startWebLogic.cmd

set "JAVA_OPTIONS=%JAVA_OPTIONS% -Dweblogic.log.Log4jLoggingEnabled=true"

How could configure Log4j2to work properly on Weblogic 14.1.2.0.0?

I've tried forcing it to activate in startWeblogic.cmd and also in setDomainEnv.cmd or setDomainEnv.sh and it still doesn't work.


Solution

  • <container-descriptor>
        <prefer-application-packages>
          <package-name>org.apache.logging.log4j</package-name>
        </prefer-application-packages>
    </container-descriptor>
    

    I added this to weblogic.xml and it worked for me.