I have configured my WildFly 18 server in domain mode format and we use log4j logger. When I checked in the server.log file, All logs from log4j are getting logged after wildfly's own logger format. Like below line 1st date and log level is from server logs and next date format and log level and log message is comming from log4j.
2021-03-19 00:13:06,623 INFO 2021-03-19 00:13:06,601 INFO [com.app.connection.service] CurrentThreadID=436 On
I search a lot...I found so many configurations related to standalone mode and some said these configurations can be done in domain.xml but nothing worked
I have the following configuration in domain.xml
<subsystem xmlns="urn:jboss:domain:logging:8.0">
<custom-handler name="CUSTOM-FILE" class="org.jboss.logmanager.handlers.PeriodicSizeRotatingFileHandler" module="org.jboss.logmanager">
<formatter>
<named-formatter name="MY-PATTERN"/>
</formatter>
<properties>
<property name="maxBackupIndex" value="24"/>
<property name="rotateSize" value="10000000"/>
<property name="suffix" value=".yyyy-MM-dd-HH"/>
<property name="append" value="true"/>
<property name="fileName" value="${jboss.server.log.dir}/server.log"/>
</properties>
</custom-handler>
<logger category="com.arjuna">
<level name="WARN"/>
</logger>
<logger category="io.jaegertracing.Configuration">
<level name="WARN"/>
</logger>
<logger category="org.jboss.as.config">
<level name="DEBUG"/>
</logger>
<logger category="sun.rmi">
<level name="WARN"/>
</logger>
<root-logger>
<level name="INFO"/>
<handlers>
<handler name="CUSTOM-FILE"/>
</handlers>
</root-logger>
<formatter name="PATTERN">
<pattern-formatter pattern="%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p %s%e%n"/>
</formatter>
<formatter name="MY-PATTERN">
<pattern-formatter pattern="%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p %s%e%n"/>
</formatter>
<formatter name="COLOR-PATTERN">
<pattern-formatter pattern="%K{level}%d{HH:mm:ss,SSS} %-5p %s%e%n"/>
</formatter>
</subsystem>
In log4j.xml, I have a console appender like below, and this log4j.xml present inside modules directory at path wildfly18.0.1\modules\org\apache\logging\log4j\main\log4j2-props
<Console name="Console">
<PatternLayout pattern="%d %-5p [%c] %m\n" />
</Console>
Following things I tried :
Added tags inside logging subsystem
<add-logging-api-dependencies value="false"/> <use-deployment-logging-config value="false"/>Added loggers
<logger category="stdout" use-parent-handlers="false">
<level name="INFO"/>
<handlers>
<handler name="CUSTOM-FILE"/>
</handlers>
</logger>
- Excluded subsystems and modules from deployments. Added following in META-INF\jboss-deployment-structure.xml
We use EAR deployment file
<deployment>
<exclude-subsystems>
<subsystem name="logging"/>
</exclude-subsystems>
<exclusions>
<module name="org.apache.commons.logging"/>
<module name="org.apache.log4j"/>
<module name="org.jboss.logging"/>
<module name="org.jboss.logging.jul-to-slf4j-stub"/>
<module name="org.jboss.logmanager"/>
<module name="org.jboss.logmanager.log4j"/>
<module name="org.slf4j"/>
<module name="org.slf4j.impl"/>
</exclusions>
</deployment>
So, please can somebody help me with the right configuration for domain mode setup?
Thanks in advance...
I'm not sure it's an option, but WildFly 22 has log4j2 support so you can configure logging with WildFly and don't need to include a log4j2.xml.
It looks like you want to redirect
stdoutto a file. If you want your log4j2 configuration to control the format, you need to change the format for yourMY-FORMATTER. Below are some CLI commands to configure the server.Note that I renamed the log file to
server-stdout.logas to not override the defaultserver.log. The reason for this is the server itself will log to this file and if you override it with that pattern then the logs from the server itself will not be formatted.Also note that anything that is written to
System.outwill end up in theserver-stout.logas well.