Log4J2 and Wildlfy 26.1.1.Final ClassCastException

1,831 views
Skip to first unread message

Jason Reed

unread,
Nov 29, 2022, 11:27:14 AM11/29/22
to WildFly
Hello,

We are attempting to get our web application using Log4j2 to run under Wildfly 26.1.1.Final. Currently we are receiving this exception on startup

Caused by: java.lang.ClassCastException: org.jboss.logmanager.log4j.JBossLoggerContext incompatible with org.apache.logging.log4j.core.LoggerContext

We have attempted to exclude the various JBoss logging used in Wildfly using the jboss-deployment-structure.xml based on many of the explained comments on StackOverflow, yet we have not yet found a solution.

So how does everyone else use Log4j2 with Wildfly 26?

J. Alejandro Zepeda Cortés

unread,
Nov 29, 2022, 2:41:23 PM11/29/22
to Jason Reed, WildFly
Hi,

We use this without issues:

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

...

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

...

if (LOGGER.isDebugEnabled())
{
LOGGER.debug("stuff");
}



--
You received this message because you are subscribed to the Google Groups "WildFly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wildfly+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/wildfly/1b754685-9a6f-4f8b-a435-5cbd70fe6720n%40googlegroups.com.


--


--------------------------------------------------
J. Alejandro Zepeda Cortés
Ing. Civil Informático
+56998184077
jalejand...@gmail.com
--------------------------------------------------

James Perkins

unread,
Nov 29, 2022, 2:51:16 PM11/29/22
to WildFly
Sorry, I accidentally replied privately instead of to the group.

The error you're seeing is because you are including log4j-core in your deployment.

The simplest solution is to just use the log4j-api and allow the logging subsystem to configure logging.

If you want to use a log4j configuration file, then you need to exclude the org.apache.logging.log4j.api module from your deployment https://docs.wildfly.org/26.1/Admin_Guide.html#how-do-i-log4j2. You then need to include the log4j-api in your deployment.

Jason Reed

unread,
Nov 30, 2022, 5:15:55 AM11/30/22
to WildFly
Thanks for that information. That should get us going on the right track.
Reply all
Reply to author
Forward
0 new messages