Ehcache 3 logging with log4j in JBoss EAP 7 not working - spring

We have below configuration,
1. Multi module web app based on JSF/Primefaces and Spring 4.2 (separate maven modules for WAR, service JAR etc.)
2. Using Log4j2 as application logging framework
3. Using Ehcache 3 with Spring Cache Abstraction annotations
4. Configured Pom.xml of service module JAR file for Ehcache 3 and java cache-api dependencies
5. Created Ehcache.xml in service module JAR
6. Configured Pom.xml of service WAR with Log4j core and slf4j-log4j12 binding dependencies
7. Configured log4j.xml with for “org.ehcache”
Versions,
JDK 1.8
Spring 4.2
Ehcache 3.3.1
Log4j 1.2
Slf4j-log4j 1.7.7
Problem we are facing,
With all this configuration in place, when we do “run on server” to WAR file on JBoss EAP 7 configured in Eclipse Neon we can’t see Ehcache related log statements in our log file. We can see our application logs though. We tried with various logging levels starting from ALL,TRACE, DEBUG but no logs in log file. Any pointers will really be helpful, we are trying to get this resolved since last 2 days but no luck.

I believe you have a mismatch in your slf4j bindings. You indicate that you are using Log4j version 2 but have placed slf4j-log4j12on the classpath. However that's the binding for log4j version 1.2.
I believe you need instead the binding for log4j 2.

Related

log4j2 behaviour different between tomcat 8.5.83 and 8.5.39

We have our web app running on tomcat 8.5.39. This app is using log4j2 correctly, applying a system property before log4j2 starts to indicate the log4j.xml configuration file. Something like:
System.setProperty("log4j.configurationFile", "/opt/ventusproxy/logs");
Now we have migrated to tomcat 8.5.83, and after this our webapp is not able to find the configuration file. Asking the log4j team, and after checking log4j debug file, it seems that, for any reason, log4j2 is starting before we set the previous system property.
We also tried 8.5.79 with the same result.
Is there any configuration change that we are missing between 8.5.39 and a later tomcat version that breaks the way log4j2 was working into our webapp until now?
Thanks,
Joan.

Spring boot deploy on Sap SCP

I need to understand how to deploy a spring boot webapp on SAP Cloud Platform.
I created a basic webapp using https://start.spring.io/.
I only added spring web as module.
I modified the generated pom excluding
spring-boot-starter-tomcat
jul-to-slf4j because I found a loop can be created by system
Then I added following dependencies as provided
slf4j-api
logback-classic
servlet-api
I added an empty web.xml, I deployed the compiled war on SCP and then I started.
After more or less 5 minutes of loading, the start fails and if I check the logs, I can't find any error.
Has anybody an idea of how I should proceed?
I even followed this tutorial, https://blogs.sap.com/2018/08/28/spring-boot-and-sap-cloud-platform-neo/, without any result.
Java version: 1.8
Tomcat version: 1.8
Spring boot version: 2.1.8.RELEASE
It looks that the problem was due to log level too low. It caused the generation of 15 mb log, apparently blocking the webapp start

Project uses Log4j2 but dependency uses Log4j

We have a new project which we're writing using Spring Boot in which we're using Log4j2 for our logging.
The problem is that we need to use an legacy library, which we own but we can't change; several other systems use it and we can't increase our scope by changing all of them.
When our project runs, it logs just fine using Log4j2, but when we make calls to the legacy library, it makes Log4j calls which throw exceptions.
Is there a way to, in our new application which uses log4j2, handle the old log4j calls?
Update
Our legacy JAR contains several JARs in an internal lib folder including:
log4j-1.2.6.jar
Our project is a Spring Boot project and we've included the dependency:
org.springframework.boot:spring-boot-starter-log4j2
The log4j JARS that I see on the projects classpath are:
spring-boot-starter-log4j2--1.5.9.RELEASE.jar
log4j-slf4-impl-2.7.jar
log4j-api-2.7.jar
log4j-core-2.7.jar
Have you tried the log4j-1.2-api adapter? Use this together with the log4j-api and log4j-core dependencies. The adapter lets applications use the Log4j 1.2 API, but routes these calls to the log4j2 implementation. See the which jars question in the FAQ.
If the application uses internal Log4j 1.2 classes this may not work but for plain logging it’s a drop-in replacement of the log4j-1.2.x jar.
Note that the legacy log4j-1.2.x jar should be removed from the classpath for this to work.
Update: if the legacy jar contains the Log4j 1.2.x jar and this causes the Log4j 1.2.x jar to be added to the classpath, the results are undefined.
I believe you have little choice but to create a custom version of this legacy jar without the Log4j 1.2.x jar. Other systems in your organization can continue to use the original legacy jar with the embedded Log4j 1.2.x jar, until they also want to migrate to Log4j2.
Your new version of the legacy jar (without embedded Log4j 1.2.x jar) may become the pathway to migrating to Log4j2 for all other systems in your organization.

Application using jboss-logging when it should use log4j

I'm upgrading a Spring MVC application from Spring 3.1 to 4.3, and Hibernate 3.6 to 5.2. I'll be running this in Wildfly 8. Dependencies are managed by Maven.
Spring uses commons-logging, which looks at the classpath of the application and attempts to choose a suitable logging framework. In my case, it seems to be choosing the wrong one. I have included log4j in my pom.xml, and checking the dependency hierarchy I can see that jboss-logging is not there. Here is the error message I'm getting:
Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.jboss.logging.Logger.debugf
So even though I don't have jboss logging in my project, commons-logging is finding it somewhere and attempting to use it, but unsuccessfully. After some searching I found jboss-logging-3.1.4.GA.jar in Wildfly.
The reason for the error is that this is an old version of jboss-logging. I added a newer jar to the server and edited module.xml to point to it, and the error went away. That proves that commons-logging is finding jboss-logging on the server.
The problem is that I don't want jboss-logging, I want log4j. How do I force commons-logging to use log4j and ignore what is on the server?
Edit: I followed the link chrisharm put up and added these lines to the standalone.xml file :
<add-logging-api-dependencies value="false"/>
<use-deployment-logging-config value="false"/>
I also changed the module.xml to point to the older jar again, since I would rather see an error if jboss is used. When I run now I get this:
Caused by: java.lang.NoClassDefFoundError: org/jboss/logging/Logger
This may be a step in the right direction, since now Spring doesn't have access to jboss-logging, but it is still trying to use it for some reason.
https://docs.jboss.org/author/display/WFLY8/How+To#HowTo-HowdoIusemyownversionoflog4j%3F
If you need/want to include your version of log4j then you need to do the following two steps.
Disable the adding of the logging dependencies to all your deployments with the add-logging-api-dependencies attribute and disable the use-deployment-logging-config attribute OR exclude the logging subsystem in a jboss-deployment-structure.xml.
Then need to include a log4j library in your deployment.
This only works for logging in your deployment. Server logs will continue to use the logging subsystem configuration.

Log4j conflicts with commons logging in a Spring RESTful integration on tomcat 6

I am trying to integrate Spring RESTful service in my project which already uses log4j. Log4j is conflicting with commonslogging and not initializing the service. I am using commons logging to compile spring jar.
If your using Maven try
<scope> provided</scope> for log4j transitive dependencies.
Issue has been resolved by including log4j.xml in my classes folder.
With all research on this topic, I come to know that jar conflict issue is with Webspehere not with Tomcat.

Resources