In the spring cloud eureka documentation:
The Eureka server is tied to log4j and doesn’t work with logback, so the dependency configuration has to be tweaked compared to a normal Spring Boot app. The spring-cloud-starter-eureka-server does this for you, but if you add logback transitively through another dependency you will need to exclude it manually, e.g. in Maven
From the SLF4J documentation:
The log4j-over-slf4j module will not work when the application calls log4j components that are not present in the bridge. For example, when application code directly references log4j appenders, filters or the PropertyConfigurator, then log4j-over-slf4j would be an insufficient replacement for log4j.
Is this what the eureka server is doing and what prevents us from using log4j-over-slf4j?
In the normal, a logging framework includes an abstraction layer and an implementation, like slf4j-api and slf4j-simple. logback is also an implementation of slf4j. When we use a logger, we use the interface in abstraction layer to do logging. It will find the implementation lib itself.
log4j-over-slf4j means we use interface in log4j, but use the slf4j implementation to do actual logging. If you use logbak as actual logging implementation, it will use log properties of slf4j, which is logbak.xml.
'The Eureka server is tied to log4j' means we use log4j interface, but spring boot add log4j-over-slf4j and logback to use slf4j logging framework.
log4j-over-slf4j module will not work when the application calls log4j components that are not present in the bridge' means you should not use the classes in the log4j implementation lib in your code. Otherwise, you can not use log4j-over-slf4j to use slf4j implementation.
Related
From the documentation I understand that it supports multiple frameworks like log4j, log4jv2 and slf4j. log4j/log4jv2/slf4j are only the API interfaces and the actual logging will be done by the jboss-logmanager classes located in the "org.jboss.log4j.logmanager" module? If that is the case what is the logger implementation used by jboss-logmanager.
Logging in WildFly is configured via the jboss-logmanager. This is an extension of JUL and does not use log4j or any other log manager. The org.jboss.log4j.logmanager module you reference is like a log4j facade in that it replaces the log4j log manager to write to the jboss-logmanager.
WildFly itself uses jboss-logging. This is simply a logging facade like slf4j.
I am migrating an application from Weblogic to JBoss EAP 6.4. The application originally used Log4J and an external logging configuration properties file. From what I understand, using Log4J would require the log4j.xml or log4j.properties file to be packaged inside the EAR and it would prevent us from changing the logging configuration at runtime.
Currently, I am ok with using the JBoss Logging subsystem to do the logging. However, the application has calls like:
Logger rootLogger = Logger.getRootLogger();
What is the equivalent in JBoss Logging, if I needed to get the RootLogger?
You can use log4j essentially as a logging facade. In other words you don't need to change your logging code at all.
If you want to use the logging subsystem for configuration just ensure your deployment does not have a log4j.xml or log4j.properties file as you stated.
If you want to swap out log4j and use JBoss Logging the equivalent for Logger.getRootLogger() would just be Logger.getLogger("").
I enabled LTW for my Spring application and as long as the advised bean in question is free of Spring's AOP features, the classes are woven properly - that is, in-method bytecode modification rather than proxies.
However, once I add tx:annotation-driven and #Transactional to that bean, all methods, even those having nothing to do with Spring features, that previously were woven with proper bytecode, now all get called via JDK proxy.
Which probably means I have to let go of tx:annotation-driven and configure AspectJ to use Spring's tx:advice for methods annotated with Spring's #Transactional.
But how do I access Spring beans from AspectJ configuration?
The only solution I found is to add AspectJ compiler to the build toolchain and implement the AbstractTransactionAspect.aj aspect and on Spring startup call TheImplementedAspect.aspectOf().setTransactionManager().
My application has slf4j logging it should use logback binding, when I try to run on jboss it uses default binding for slf4j in jboss. It throws multiple binding error as it finds logback and jboss binding both. Also I am using slf4j1.7.2 with logback 1.0.9 but I receives error saying SLF4J: The requested version 1.6 by your slf4j binding is not compatible with [1.5.5, 1.5.6, 1.5.7, 1.5.8]
Please help me on this
The step by step guide is at:
http://jaitechwriteups.blogspot.com/2010/04/eclipse-logback-plugin-with-jboss-as.html
The key is to have a class-loader isolation defined in your jboss-web.xml (assuming it is for web app)
Other links that may be helpful (I have to put the links as text as I'm not allowed to put more than 2 links in a post)
http://blog.frankel.ch/configuring-maven-to-use-slf4j
http://www.javacodegeeks.com/2012/07/junit-logback-maven-with-spring-3.html
If you are using Maven please remember:
you have to make sure your libraries are not pulling older versions of slf4j by their dependencies, declare it directly if needed
you do not have log4j in your WEB-INF/lib, if some of your libraries depend on log4j or commons-logging declare relevant bridges (see links above or http://www.slf4j.org/faq.html#excludingJCL)
We are using a 3rd-party jar that contains a dependency to the log4j.varia.NullAppender class. We are transitioning to logback, but unable to change the 3rd-party jar, so we plan to use the log4j-over-sl4j bridge for now with the rest of our code still using the existing log4j calls.
Since the log4j-over-slf4j jar does not contain the NullAppender class, what is the best way to spoof it? Should we write our own and put it on the class path? Should we augment the log4j-over-slf4j bridge jar with this class?
What have others done who have run into this and does the logback project plan to support backwards compatibility? This is a real hassle for those of us who want to migrate when existing jar files use log4j classes that are not in the bridge.
Any suggestions or best practices?