How to let JBoss not to affect my own log4j2 settings? - log4j2

I'm using Log4j2(2.17.1) with two type of configs(log4j.prop & log4j2.xml) on multiple projects. My APP's log4j2 works properly on Tomcat 9 while reading external log4j config. But somehow it stops working or only logging into server.log when I deploy my APP onto JBoss EAP 7. So I think the problem is coming from JBoss, and I need a way to tell it don't mess with my own Log4j2. Does anyone know how to do it?

With JBoss EAP 7.4 there is a new module which delegates the log4j-api logs to the jboss-logmanager. If you want to use the log4j log manager (log4j-core) then you need to exclude some modules from your deployment.
Option 1 below I would say is preferred since it only affects a single deployment. Option 2 will affect all deployments.
Option 1
Add a jboss-deployment-structure.xml to your deployment:
<jboss-deployment-structure>
<deployment>
<exclusions>
<module name="org.apache.logging.log4j.api" />
</exclusions>
</deployment>
</jboss-deployment-structure>
Option 2
Change the add-logging-api-dependencies attribute in the logging subsystem to false.
CLI example:
/subsystem=logging:write-attribute(name=add-logging-api-dependencies, value=false)

The root cause for this issue is related to the "ClassLoader" which is searched by JBoss EAP Logging in order to find the appropriate logging provider implementation. This search is made in the following order:
JBoss EAP LogManager
Log4j
Slf4j
JDK logging
Since both JBoss EAP LogManager and Log4j2 are available in the classpath, the JBoss EAP LogManager will be utilized due to the "higher precedence". For this reason, you must set the use-deployment-logging-config=false in the logging subsystem.
Furthermore, the JBoss EAP LogManager also uses classes from Log4j2 in its own implementation. That's why the modules, org.apache.log4j and org.apache.commons.logging have to be excluded from the deployment in order for Log4J2 to work correctly.

Related

Replace Java Util Logging with Log4j2 specific to web application on tomcat

I have a java application deployed on tomcat 9+. I am aware how to change the default tomcat logging to instead use log4j2.
I have done this by following this https://logging.apache.org/log4j/2.x/log4j-appserver/index.html.
I wanted to know rather than changing the default tomcat logging to use log4j2 is it possible to use log4j2 only for my war file without changing the code. My application has used JUL for logging purpose.
These days almost any logging configuration is possible.
Tomcat uses a special JUL LogManager (cf. ClassLoaderLogManager) that allows to specify a different JUL configuration in every application.
To redirect all JUL logs from your application to Log4j2 the easiest way is to pass through SLF4j. To do this:
Add jul-to-slf4j and slf4j-api to your project,
Add a WEB-INF/classes/logging.properties configuration file that redirects everything to the SLF4JBridgeHandler:
handlers = org.slf4j.bridge.SLF4JBridgeHandler
.handlers = org.slf4j.bridge.SLF4JBridgeHandler
Add the Log4j 2.x dependencies to your project: log4j-core, log4j-api and log4j-web and the SLF4j binding log4j-slf4j-impl.
Configure Log4j 2.x as you wish.
Warning: There is a performance penalty in this solution (cf. SLF4j documentation).

Trying to get log4j1.x to work alongside log4j2.x

I have successfully migrated our application from log4j 1.x to log4j 2.x.
But there is one external component which cannot be migrated. Meaning calls to log4j 1.x should remain as they are.
I have log4j2.xml for our application and the old log4j.properties for the external component.I am getting the logs for the appenders in log4j2.xml but nothing for the one defined in log4j.properties. I read the post -
Mixing log4j 1.x and log4j 2
and have added the required jars. Earlier with log4j 1.x we used to have 2 log4j.properties - one for the applciation and another one for the external component using PropertyConfigurator. Now with log4j2.xml I am not sure how we can achieve this.
Configuring log4j2 and log4j using a single log4j2 xml file
This post says we cannot have log4j.properties in the classpath. Does that mean that I need to transfer all the appenders defined in log4j.properties to log4j2.xml ? Can I have a seperate log4j2.xml just for the external component.
You cannot have two log4j2.xml configurations (well, separate web apps can have separate configurations but in general each process has one config).
Option 1: The easiest thing to do is to use the bridge log4j-1.2-api-2.x.jar and merge the log4j.properties configuration into the log4j2.xml. Then all logging is done by lo4j 2 and it should all work.
If you want to do things the hard way you may be able to succeed but it may take some fiddling.
Option 2: If by "migrated our application from log4j 1.x to log4j 2.x" you mean your application now uses the log4j 2 API, then you should be able to use both log4j 1.x to log4j 2 at the same time. (log4j 1.x for the external component.)
In that case, do not use the bridge log4j-1.2-api-2.x.jar. If you use the bridge, it will route calls to the log4j 1.x API to log4j 2. Usually that is what you want, but in this case it sounds like your external component wants to use the log4j 1.x internals. (Is this true? If not, consider option 1.)
If your application now uses the log4j 2 API, except for the external component, then put these jars and config files in your classpath:
log4j-api-2.x.jar
log4j-core-2.x.jar
log4j-1.2.x.jar
log4j2.xml - the log4j 2 configuration for your application
log4j.properties - the log4j 1.x configuration for the external component
But again, simply merging the configurations is probably easier to maintain.

How to invoke MBeans from command prompt in Wildfly 8.2.0

I have below queries.
Is there any way to access JBoss MBeans in EAP 6 (wildfly 8.2.0) through Command Line like twiddle in EAP 5 (JBoss 6 AS) ?
Whether JBoss EAP 6 has any command line tool (like twiddle.sh) to invoke custom MBeans ?
Please help. Thanks.
Domain mbeans are out of the jbosscli scope at the moment, so it seems from this jboss issue https://issues.jboss.org/browse/PRODMGT-425

WSO2 Carbon 4.x JNDI Tomcat

WSO2 Registry 4.5.x based on Carbon 4.x plattform allows to deploy WARs. For configuration of resources I want to use JNDI.
As described here, I try to configure JNDI resources:
http://kishanthan.wordpress.com/2012/05/31/how-to-register-jndi-resources-for-webapps-in-wso2-application-server/
1) WEB-INF/web.xml
<resource-ref>
<res-ref-name>url/ZoneConfiguration</res-ref-name>
<res-type>java.net.URL</res-type>
<res-auth>Container</res-auth>
</resource-ref>
2) META-INF/context.xml
<Context debug="5" reloadable="true" crossContext="true">
<ResourceLink name="url/ZoneConfiguration" global="url/ZoneConfiguration" type="java.net.URL"/>
</Context>
3) $CARBON_HOME/repository/conf/tomcat/catalina-server.xml:
<GlobalNamingResources>
<Resource name="url/ZoneConfiguration" factory="org.jee.jndi.URLResourceFactory"
type="java.net.URL" url="file:///temp/local.zone.properties"/>
</GlobalNamingResources>
(about factory: see here http://tomcat.apache.org/tomcat-7.0-doc/jndi-resources-howto.html#Adding_Custom_Resource_Factories)
The library with URLResourceFactory is deployed in $CARBON_HOME/lib/endorsed
This configuration works in a Tomcat 7.x but not in the WSO2 Tomcat. I am inclined to file an issue.
Or am I lacking anything WSO2 specific?
WSO2 Registry 4.5.X does not support hosting webapps out of the box, unless you have installed the webapp management feature on top of WSO2 Registry.
You can find more info related to JNDI Resources configurations from this post [1]. A sample is also included in that post which demonstrates the configurations and accessing resources defined as global naming resources with custom resource factory implementation.
[1] http://kishanthan.wordpress.com/2012/05/31/how-to-register-jndi-resources-for-webapps-in-wso2-application-server/

Deploying Grails Atmosphere app in JBoss 7

Greeting,
I'm trying to make this example work in Grails 2.1 using atmosphere plugin. When running in development environment on Tomcat it does not work, probably because Tomcat does not support web-services.
So I'm deploying it on JBoss 7.1. It does not work as well. And the following exception could be found in the log file
AtmosphereFramework exception: java.lang.IllegalStateException: The servlet or filters
that are being used by this request do not support async operation
I found the article related to async servlets support in Grails. Seems that Servlet3AsyncWebXmlProcessor should add async support to web.xml. But somebody should invoke it.
I think that atmosphere plugin is responsible for allowing async communication.
Have I missed something? Could you please help to make it work on AS7?
Ideally, I would like to figure out the way of running atmosphere applications in development environment? Is it possible?

Resources