Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run WildFly-8.x with log4j2 & slf4j

I like to replace the standard logging mechanism in my WildFly-8.x with log4j2.

My idea of doing this was adding the following jars as modules:

log4j-api-2.3.jar
log4j-core-2.3.jar

and adding a module.xml to have the logger provided by the server.

Since I alredy use slf4j in my application, which is built via Maven, I decided to simply add the following stuff into my pom.xml for building my EAR-file

  <!-- versions are provided via private parent-pom -->
  <!-- slf4j-api -->
  <dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <scope>provided</scope>
  </dependency>
  <!-- slf4j to log4j2, needed??? -->
  <dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-slf4j-impl</artifactId>
    <scope>provided</scope>
  </dependency>
  <!-- log4j2 api, do I really need this??  -->
  <dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-api</artifactId>
    <scope>provided</scope>
  </dependency>
  <!-- log4j2 api, do I really need this?? -->
  <dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-core</artifactId>
    <scope>provided</scope>
  </dependency>

So, a few questions remain:

1.) Do I need additional dependencies in my jboss-deployment-structure.xml, something that looks like this?

[...]
<ear-subdeployment-isolated>false</ear-subdeployment-isolated>
<deployment>
  <dependencies>
    [...]
    <!-- name taken from my introduced module.xml -->
    <module name="org.apache.logging.log4j2" slot="main" export="true" />
    [...]
  </dependencies>
</deployment>

2.) How do I configure log4j2 in my standalone-*.xml? I guess the <loggers/> and <handlers/> will only work with the built-in system?

3.) Do I need to specify the pom.xml snippet above into every maven module where I log something (which is nearly every module where a java class resides)?

And a little "candy" question: 4.) How do I setup log4j2 to compress logfiles, as it was done with log4j(1)-extras?

like image 321
Robert Heine Avatar asked Jun 24 '15 09:06

Robert Heine


1 Answers

I hope this link help you, it contains alternative logging framework for most of AS

and for your question 4

How do I setup log4j2 to compress logfiles, as it was done with log4j(1)-extras?

you can configure it like the below

filePattern="logs/app-%d{MM-dd-yyyy}.log.gz" 

if you are using RollingFile appender

like image 78
m.hassaballah Avatar answered Sep 22 '22 10:09

m.hassaballah