A Core Java Logger Adapter that will give you the possibility to write Logger independent code.
I compiled this with the Open JDK8. Previous versions at maven central are build ith JDK10. I went away from the JDK10, because most projects I know, are using JDK8 in production right know. But, if you want to use this with JDK9/10/11/... you can use it.. it is working perfect! Only if you start using the JMS, it could be helpful to add a module-info.java Add the following lines, switch inside the pom.xml to the JDK version you prefer, start a mvn clean install and be happy ;-)
module rapidpm.dependencies.core.logger {
requires log4j;
requires transitive java.logging;
requires slf4j.api;
requires org.apache.logging.log4j;
exports org.rapidpm.dependencies.core.logger;
}
- OpenJDK
- Oracle
- Oracle - GraalVM
- Amazon
- IBM
- Adopt-OpenJ9
- Zulu
- Liberica
- JDK 6
- JDK 7
- JDK 8
- JDK 9
- JDK 10
- JDK 11
- JDK 12
- JDK 13
- JDK 14
In every project, there is the decision of what logger framework should be used. The bad thing here is, whatever you are choosing, it will be the wrong one. Other projects or frameworks are using different logger frameworks. So I decided to create a simple, robust solution that will give me the freedom to stop worrying about it. At runtime, this Adapter will check what logging framework is available in the classpath and will transparently use this.
To use this you have two possibilities. However, the first step is to add the dependency to your pom.xml. Second step is, chooseing the way you want to define a Logger.
Define a class attribute.
LoggerService logger = Logger.getLogger(getClass());
You can implement an interface, that will give you a method to get the logger. The interface provides a default - implementation, so there is nothing additional to do for you. This solution is perfect for web apps as well because you don´t have to worry about Serializable.
MyClass implements HasLogger {}