Using Log4j2 with Jboss EAP6.4

961 views
Skip to first unread message

Harvinder Singh

unread,
Jan 26, 2022, 9:53:55 AM1/26/22
to WildFly
We are trying to use log4j2 with JBoss Eap 6.4 but seems JBOSS is giving priority to log4j1 that comes with it. 
What we tried is that we disabled logging subsystem from JBoss and provided log4j2 jar and configuration through the deployment war.
When we tried this on WildFly 8.2 on the dev machine, we saw this working but as soon we moved to JBoss EAP 6.4 there we noticed log4j1.x (using OOB logging.properties) is writing to server.log instead and log4j2 is writing to previous day file.

Please provide some guidance if anyone has tried this already.

James Perkins

unread,
Jan 26, 2022, 10:46:03 AM1/26/22
to WildFly
How did you disable the logging subsystem? If you exclude the org.apache.log4j module or the logging subsystem from your deployment with a jboss-deployment-structure.xml it should work. You also need to include log4j 2 as well.

Harvinder Singh

unread,
Jan 27, 2022, 1:27:53 AM1/27/22
to WildFly
Thanks for replying James.

We tried two approaches-
1. We excluded logging subsystem from deployment with a jboss-deployment-structure.xml and added log4j2 dependency (by adding module and jar in Jboss And also tried adding in WAR). It still picks log format defined in standalone.xml
2. We removed logging subsystem from the Standalone.xml itself and provided log4j2 jar and log4j2.xml in WAR. - This way it started picking log4j2. But now the problem is that its writing to previous day file only and current day file is written as per logging.properties(that comes with Jboss) format. Below is how our RollingFileAppender is configured
                <RollingFile name="LogFileAppender"
                        fileName="${logsfileLocation}/server.log"
                        filePattern="${logsfileLocation}/server.log.%d{yyyy-MM-dd}">
                        <PatternLayout>
                            <Pattern>%d %-5p [%c] (%t) %m%n</Pattern>
                          </PatternLayout>
                        <Policies>
                                <OnStartupTriggeringPolicy minSize="0"/>
                                <TimeBasedTriggeringPolicy interval="1" modulate="true"/>
                        </Policies>
                        <LevelRangeFilter minLevel="ERROR" maxLevel="INFO" onMatch="ACCEPT" onMismatch="DENY"/>
                </RollingFile>

James Perkins

unread,
Jan 27, 2022, 2:47:16 PM1/27/22
to WildFly
On Wednesday, January 26, 2022 at 10:27:53 PM UTC-8 harry...@gmail.com wrote:
Thanks for replying James.

We tried two approaches-
1. We excluded logging subsystem from deployment with a jboss-deployment-structure.xml and added log4j2 dependency (by adding module and jar in Jboss And also tried adding in WAR). It still picks log format defined in standalone.xml

What do you mean by "adding a module"? Do you mean you created something like a org.apache.logging.log4j module? If so you'd need to likely add some system properties as to where to find the configuration file. I'd suggest including the configuration file and libraries in your WAR itself.
 
2. We removed logging subsystem from the Standalone.xml itself and provided log4j2 jar and log4j2.xml in WAR. - This way it started picking log4j2. But now the problem is that its writing to previous day file only and current day file is written as per logging.properties(that comes with Jboss) format. Below is how our RollingFileAppender is configured
                <RollingFile name="LogFileAppender"
                        fileName="${logsfileLocation}/server.log"
                        filePattern="${logsfileLocation}/server.log.%d{yyyy-MM-dd}">
                        <PatternLayout>
                            <Pattern>%d %-5p [%c] (%t) %m%n</Pattern>
                          </PatternLayout>
                        <Policies>
                                <OnStartupTriggeringPolicy minSize="0"/>
                                <TimeBasedTriggeringPolicy interval="1" modulate="true"/>
                        </Policies>
                        <LevelRangeFilter minLevel="ERROR" maxLevel="INFO" onMatch="ACCEPT" onMismatch="DENY"/>
                </RollingFile>

I wouldn't suggest removing the logging subsystem. Log messages from the server will not be configurable at runtime and would require manual changes to the logging.properties file.

Harvinder Singh

unread,
Jan 28, 2022, 6:15:56 AM1/28/22
to James Perkins, WildFly
Hi James, 

I have added my comments inline. Please suggest what final approach you see we should rather use.

Thanks a lot.

On Fri, Jan 28, 2022 at 1:17 AM James Perkins <jper...@redhat.com> wrote:


On Wednesday, January 26, 2022 at 10:27:53 PM UTC-8 harry...@gmail.com wrote:
Thanks for replying James.

We tried two approaches-
1. We excluded logging subsystem from deployment with a jboss-deployment-structure.xml and added log4j2 dependency (by adding module and jar in Jboss And also tried adding in WAR). It still picks log format defined in standalone.xml

What do you mean by "adding a module"? Do you mean you created something like a org.apache.logging.log4j module? If so you'd need to likely add some system properties as to where to find the configuration file. I'd suggest including the configuration file and libraries in your WAR itself.
 [Harvinder]: Yes we tried both ways
1. First, by adding module and giving path by system properties (-Dlogging.configuration=file:/WildFly/standalone/configuration/log4j2.xml") - This way logging stopped working.
2. Second, by adding configuration file and libraries in WAR 

 
2. We removed logging subsystem from the Standalone.xml itself and provided log4j2 jar and log4j2.xml in WAR. - This way it started picking log4j2. But now the problem is that its writing to previous day file only and current day file is written as per logging.properties(that comes with Jboss) format. Below is how our RollingFileAppender is configured
                <RollingFile name="LogFileAppender"
                        fileName="${logsfileLocation}/server.log"
                        filePattern="${logsfileLocation}/server.log.%d{yyyy-MM-dd}">
                        <PatternLayout>
                            <Pattern>%d %-5p [%c] (%t) %m%n</Pattern>
                          </PatternLayout>
                        <Policies>
                                <OnStartupTriggeringPolicy minSize="0"/>
                                <TimeBasedTriggeringPolicy interval="1" modulate="true"/>
                        </Policies>
                        <LevelRangeFilter minLevel="ERROR" maxLevel="INFO" onMatch="ACCEPT" onMismatch="DENY"/>
                </RollingFile>

I wouldn't suggest removing the logging subsystem. Log messages from the server will not be configurable at runtime and would require manual changes to the logging.properties file.
[Harvinder] : If we don't remove the logging subsystem. It doesn't pick the log pattern defined in our log4j2.xml but rather from the logging subsystem defined under standalone.xml. In that case what is the use of providing our log4j2.xml 
 

On Wednesday, 26 January 2022 at 21:16:03 UTC+5:30 jper...@redhat.com wrote:
How did you disable the logging subsystem? If you exclude the org.apache.log4j module or the logging subsystem from your deployment with a jboss-deployment-structure.xml it should work. You also need to include log4j 2 as well.

On Wednesday, January 26, 2022 at 6:53:55 AM UTC-8 harry...@gmail.com wrote:
We are trying to use log4j2 with JBoss Eap 6.4 but seems JBOSS is giving priority to log4j1 that comes with it. 
What we tried is that we disabled logging subsystem from JBoss and provided log4j2 jar and configuration through the deployment war.
When we tried this on WildFly 8.2 on the dev machine, we saw this working but as soon we moved to JBoss EAP 6.4 there we noticed log4j1.x (using OOB logging.properties) is writing to server.log instead and log4j2 is writing to previous day file.

Please provide some guidance if anyone has tried this already.

--
You received this message because you are subscribed to a topic in the Google Groups "WildFly" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/wildfly/g1k7dDT1NG0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to wildfly+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/wildfly/8cfb2084-bcdf-49c9-9d3c-5b6f8d88f736n%40googlegroups.com.

James Perkins

unread,
Jan 28, 2022, 10:46:15 AM1/28/22
to WildFly
You don't want to completely remove the logging subsystem as that is how the server itself is configured. I assume you only want your application to use log4j2. You'd need to use a jboss-deployment-structure.xml to remove the logging subsystem from your deployment.

That said EAP 6.4 does not ship log4j2 so there really shouldn't be too much you need to do. Unless you're using log4j 1, slf4j or jboss-logging in your deployment. If all your loggers are log4j-api (log4j2) loggers then you should just need to include log4j-api and log4j-core in your deployment along with a configuration file.

Reply all
Reply to author
Forward
0 new messages