Wildfly 20 deployment-logging-config NOT working

422 views
Skip to first unread message

Arnie Morein

unread,
Jan 8, 2021, 5:51:15 PM1/8/21
to WildFly

I have a maven multi-module project (ear, ejb jars, war) that is acting odd. If I deploy a log4j2.xml file in WEB-INF/classes, it is detected and all the rolling file appenders are deployed.
I use slf4j through out my application so that I do not have to code against log4j's API.
Everything compiles and deploys. On the WF console I see messages.
But the files are all empty.
I've put a log4j.xml (or log4j2.xml) in each jar's META-INF
folder, but alas, they are NOT detected.
I have tried putting the log4j.xml in the root of the ear file, in the./lib folder, in META-INF folder.
Nothing works.
This used to work just fine on EAP 4 back in the day.
I've seen examples of adding appenders and loggers to the WF server configuration but I do NOT want to put all that in there. It should work from w/i the EAR and its modules.

James Perkins

unread,
Jan 11, 2021, 5:13:44 PM1/11/21
to WildFly
What log manager do you want to use? Do you have a jboss-deployment-structure.xml which excludes the logging subsystem?

Arnie Morein

unread,
Jan 13, 2021, 5:33:23 PM1/13/21
to WildFly
The intention was to use the log4j that is in the server, rather than exclude it; if possible, as I have coded to the slf4j API instead. I have added:

            <module name="org.apache.log4j" export="true" />
            <module name="org.apache.logging.log4j" export="true" />

to my jboss-deployment-structure file's dependencies section with no avail.

Where should the log4j.xml files be placed for each module (or should it be in the EAR)? Or should it/they be log4j2.xml ?

James Perkins

unread,
Jan 14, 2021, 10:56:17 AM1/14/21
to WildFly
To use a log4j configuration, only log4j 1.x would work BTW with a config, you can't use slf4j without some changes. By default the slf4j binding is to the jboss-logmanager since that's what the server uses. You've got a couple options though. If you want to use log4j as the log manager then you'll need to exclude the org.slf4j and org.slf4j.impl modules in the jboss-deployment-structure.xml and include the libraries in your EAR.

The other option would be to use either a logging.properties in your deployment which conforms to a jboss-logmanger configuration or use a logging profile. Are there special log4j appenders you want to use?

Arnie Morein

unread,
Jan 14, 2021, 4:12:11 PM1/14/21
to WildFly
Oh yes, most definitely. In the environment, all "logs" are sent to a separate volume mounted as /logs. Under there is the /app_name folder, and in there are all the various appenders. There's a lot of traffic so several files to make managing/querying them easier.

Arnie Morein

unread,
Jan 15, 2021, 12:47:37 PM1/15/21
to WildFly
Ok, so to clarify, I can use log4j.1x since it comes with the server as long as I exclude it in the xml and include it in the ear.
But putting log4j.xml (and .dtd) in each jar's /META-INF and in the /WEB-INF/classes folder did not work. Nothing is started.
So somehow the auto detection isn't working?
And my only option is a logging.properties file on WF?

James Perkins

unread,
Jan 15, 2021, 1:13:51 PM1/15/21
to WildFly
On Friday, January 15, 2021 at 9:47:37 AM UTC-8 arnie....@gmail.com wrote:
Ok, so to clarify, I can use log4j.1x since it comes with the server as long as I exclude it in the xml and include it in the ear.

Really if you exclude the logging dependencies or the logging subsystem from processing your deployment you can use any log manager. However you'd need to include any log dependencies you need in your application.
 
But putting log4j.xml (and .dtd) in each jar's /META-INF and in the /WEB-INF/classes folder did not work. Nothing is started.

This might not work as expected in general. It might work if you did that and put a log4j and slf4j library in each WAR too. However it wouldn't work for JAR's.
 
So somehow the auto detection isn't working?

What the auto-detect does is look for a log4j.xml and configure the servers log4j module to work for each configuration it finds. This only works if you're using log4j loggers though. It does not work for slf4j loggers though. While I haven't tested it _might_ work if you exclude the slf4j modules and include your own version of slf4j and the log4j-slf4j binding in your EAR.
 
And my only option is a logging.properties file on WF?

That's just an option is all since all the logging API's provided by the server delegate to the jboss-logmanager.

Arnie Morein

unread,
Jan 15, 2021, 6:04:26 PM1/15/21
to WildFly

I created a new ejb module with the log4j.xml and .dtd file in the root of the jar and added it to the EAR. Despite being the first EJB module in application.xml, it isn't deployed until just before the WAR. But at least now I see log4j being configured via the system's debug statements:

2021-01-15 16:22:04,467 INFO  [stdout] (ServerService Thread Pool -- 107) 2021-01-15 16:22:04,467 ServerService Thread Pool -- 107 DEBUG Starting LoggerContext[name=APP NAME,org.apache.logging.log4j.core.LoggerContext@23cc8efa] with configuration XmlConfiguration[location=vfs:/C:/dev/jboss/wildfly-21.0.2.Final/bin/content/les-facialrecog-bus-1.0.0.ear/les-facialrecog-bus-log-config.jar/log4j2.xml]...

And all the files are created. As the application runs, messages come up on the WF console (warn, error).

But the files remain empty. I'll let it run for a while; perhaps the rollingfileappenders are buffered?

James Perkins

unread,
Jan 18, 2021, 10:45:50 AM1/18/21
to WildFly
That looks like log4j2 which would change things up a bit depending on the version of WildFly you're using. Do you only use slf4j as the logging facade?

Arnie Morein

unread,
Jan 20, 2021, 5:52:16 PM1/20/21
to WildFly
Yes, only SLF4J in my code. Log4j2 as the "implementation". I set all the server stuff as blocked and included my own jars in the ear/lib.
I created a project_name-log-config EJB jar module and all it contains is the log4j2.xml, log4j.dtd in the root and the beans.xml, ejb-jar.xml in the META-Inf folder.
It does get deployed but LAST and though the entire config is started (all the files are there) there is never any logging. It is the first EJB listed in application.xml.
Am I going to have to set up some kind of @Depends to get it deployed first?

James Perkins

unread,
Jan 20, 2021, 8:08:48 PM1/20/21
to WildFly
Is there a reason not to put the log4j configuration in the EAR/META-INF?

Arnie Morein

unread,
Jan 21, 2021, 9:12:40 AM1/21/21
to WildFly
No, but the last time I tried that it didn't do anything. But that was when I was trying to use the server libraries.
Let me try it now that I'm including my own.
Message has been deleted

Arnie Morein

unread,
Jan 23, 2021, 5:12:14 PM1/23/21
to WildFly
With log4j2.xml (and .dtd) in the ear's META-INF, nothing. Renamed to log4j.xml, nothing. Moved both to root of ear, nothing.
Has no one tested this yet? I can find no real documentation on doing this.
I restored my EJB module that has nothing but the config files and I see where it is deployed. BUT, log4j doesn't start until the war module is started.
Adding log4j-web to the WAR module's WEB-INF/lib folder sorta of works but only once the servlet context is started.

So I added a @Singleton/@Startup EJB to the config-log module of the ear. In the @PostConstruct method, it starts up log4j;
BUT that method is NOT called until the startup of the WAR!
HOW IS THAT POSSIBLE?!
Since when is the lifecycle of a WAR module controlling the life cycle of an EJB in a different deployment?!

This is idiotic. I do not understand by log4j2 doesn't auto-start on its own from each module, but I guess there's no standard/spec for that?
Even with the log4j2 api, core, and slf4j jars in the EAR/lib.

James Perkins

unread,
Jan 25, 2021, 11:39:35 AM1/25/21
to WildFly
This looks like a possibly limitation with log4j2. Have you read over http://logging.apache.org/log4j/2.x/manual/webapp.html? It looks like you're supposed to use the log4j-web dependency. Maybe I'm missing something obvious, but it doesn't seem real clear to me how it works with an EAR https://logging.apache.org/log4j/2.x/manual/logsep.html#Java_EE_Applications.

Arnie Morein

unread,
Jan 26, 2021, 2:34:21 PM1/26/21
to WildFly
The log4j2-web - " The Web module provides support for automatically enabling Log4j in Servlet containers. " so turning on log4j2 from an EJB module in an EAR seems dead.

That said, if I define appenders and loggers in Wildfly, my code should be able to access them, right?

James Perkins

unread,
Jan 26, 2021, 2:37:19 PM1/26/21
to WildFly
On Tuesday, January 26, 2021 at 11:34:21 AM UTC-8 arnie....@gmail.com wrote:
The log4j2-web - " The Web module provides support for automatically enabling Log4j in Servlet containers. " so turning on log4j2 from an EJB module in an EAR seems dead.

That said, if I define appenders and loggers in Wildfly, my code should be able to access them, right?

Not log4j2 appenders. Is there something special you want to use with log4j2?

Arnie Morein

unread,
Jan 26, 2021, 6:17:59 PM1/26/21
to WildFly
Nothing special, just what I have been using for a while; I can down grade, though I do need a rollingFile appender.

James Perkins

unread,
Jan 26, 2021, 6:21:36 PM1/26/21
to WildFly
Okay in that case you could look at the periodic-rotating-file-handler, size-rotating-file-handler, periodic-size-rotating-file-handler or use a custom-handler with the log4j1 appender. That's assuming you're okay using the logging subsystem. If not you could use a log4j1 configuration file or a logging.properties in the JBoss Log Manager format to get logging for your deployment. There are also logging profiles which you can assign to a deployment and manage via the logging subsystem.
Reply all
Reply to author
Forward
0 new messages