How to use log4j2 in a ShrinkWrap container?

305 Views Asked by At

I try to use a unified logging in my project as well as the Arquillian tests, but for some reason the Wildfly for the ShrinkWrap containers does not use my log4j2.xml logging configuration.

My deployment container is setup in the test like this:

@Deployment
public static Archive<?> createDeployment() {
  PomEquippedResolveStage pomFile = Maven.resolver().loadPomFromFile("pom.xml");

  WebArchive archive = ShrinkWrap.create(WebArchive.class)
      .addAsLibraries(pomFile.resolve("org.mockito:mockito-all").withTransitivity().asFile())
      .addAsLibraries(pomFile.resolve("org.slf4j:slf4j-api").withTransitivity().asFile())
      .addAsLibraries(pomFile.resolve("org.slf4j:jcl-over-slf4j").withTransitivity().asFile())
      .addAsLibraries(pomFile.resolve("org.apache.logging.log4j:log4j-slf4j-impl").withTransitivity().asFile())
      .addClasses(/* the required classes*/)
      .addAsResource("log4j2.xml")
      .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");

  return archive;
}

I explicitly add the slf4j and the log4j implementation, which works fine for the rest of the project. How do I enable log4j2 here properly?

1

There are 1 best solutions below

0
On BEST ANSWER

It seems to work now. I made a mistake with the error level in my log4j2.xml, so only the standard output of the Wildfly was shown.

The example above works.