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

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.

Related

Why does spring-boot-starter-logging require a dependency on log4-to-slf4j

I have a Spring Boot 2.6.3 project that uses spring-boot-starter. When I run the dependecy:tree goal in maven, I see that spring-boot-starter-logging depends on both logback and (indirectly) log4j. Why does spring-boot-starter-logging require a dependency on log4-to-slf4j?
Spring Boot has bindings for all major logging frameworks. With a single configuration you can concentrate logs sent through SLF4J, Log4j 2.x API or java.util.logging.
Therefore the spring-boot-starter-logging provides:
a binding for SLF4J (logback-classic),
an implementation of the Log4j 2.x API (log4j-to-slf4j). Remark that this is not the standard Log4j 2.x Core implementation.
a handler for java.util.logging (jul-to-slf4j).
Remark that spring-boot-starter-log4j2 does the same thing and redirects the frameworks above to Log4j 2.x Core.
The big absent in this picture is Jakarta Commons Logging, which is only able to bind to java.util.logging (hence not directly to neither Logback nor Log4j 2.x Core). However spring-core depends on spring-jcl, which binds JCL directly to SLF4J or the Log4j 2.x API and can entirely replace the original JCL.
A fifth API (Log4j 1.x) was supported in Spring Boot 1.x.

Logback support in Quarkus

I have tried to add logback in Quarkus, but later realised Quarkus does not support logback. If I am wrong, May I know how logback can be configured in Quarkus with an example. Thanks in advance.
No, in Quarkus, we standardized on using JBoss Logging for the logging.
And AFAIK we don't even have a bridge from logback to JBoss Logging as for some other logging components so you can't even use the Logback API in your application.
In currrent version 1.6.0.final of Quarkus You can use one of the Logging API's below
JDK java.util.logging
JBoss Logging
SLF4J
Apache Commons Logging
https://quarkus.io/guides/logging
There is a Quarkus extension which enables logback: https://quarkiverse.github.io/quarkiverse-docs/quarkus-logging-logback/dev/index.html
However there are some restrictions, mostly due to internal Quarkus specifics:
Your Quarkus version should match version used for 'quarkus-logging-logback' extension build
If you want to use own appenders/listeners in 'logback.xml' - you should put them in separate library and include them in your project through library

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.

Ehcache 3 logging with log4j in JBoss EAP 7 not working

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.

using slf4j to log in spring when I can't get rid of commons-logging

I'm using some a component other than Spring that has a commons-logging dependency.
So, excluding commons-logging from the spring dependency doesn't get rid of it, and so the instructions here aren't helping. Is there some more declarative way to push Spring 3.0.5 to talk to slf4j?
I had an issue on Tomcat 6 where Commons Logging wouldn't play nice with SLF4J which got dragged in from Hibernate. We had configured Commons Logging to go to Log4J anyway. After explicitly including "slf4j-log4j 1.6.1" and its "jcl-over-slf4j 1.6.1" component to take out Commons Logging, I still got errors from Commons Logging. The answer lied in this blog post: You explicitly include Commons Logging at version "99.0-does-not-exist". This includes an empty JAR, so that only the SLF4J code gets executed now.
If you are using Maven, please read the FAQ entry about excluding commons-logging.
Use the SLF4j bridge

Resources