My web application is using Java, Hibernate's JPA implementation (EntityManager) and Spring. What are my logger choices and what would you recommend. Ideally the configuration would be simple (one config file for Hibernate, Spring and my code).
If you are using Spring Boot Starters, Logback will provide a good support for logging. Besides, Logback also provides a use of good support for Common Logging, Util Logging, Log4J, and SLF4J.
Hibernate utilizes Simple Logging Facade for Java (SLF4J) in order to log various system events. SLF4J can direct your logging output to several logging frameworks (NOP, Simple, log4j version 1.2, JDK 1.4 logging, JCL or logback) depending on your chosen binding.
One of the most popular solutions for the Java world is the Apache Log4j 2 framework. Maintained by the Apache Foundation, Log4j 2 is an improvement on the original Log4j, which was the most popular logging framework in Java for many years.
We do use Log4j during development of the Hibernate libraries as it's a dependency of our testsuites; therefore we've still upgraded all branches. These test dependencies won't be included in your application if you depend on the Hibernate libraries. The upgraded versions of each project are: Hibernate ORM: 5.3.
When building applications out of various frameworks you often need to wrap existing loggers, be they log4j or JUL or JULI or whatever. The standard application for this is the Simple Logging Facade for Java (SLF4J). Even if your app doesn't need SLF4J now you may later want to add a library that does need it, and it's your best hope for one config file in the long run.
With that in mind you should stick to logging packages that SLF4J supports, but usually it boils down to java.util.logging (JUL) or Apache's log4j. This has been a subject for debate for some time and you can find many opinions on both sides.
Personally, I think it's unfortunate that Java logging is in this situation, and I'll use whatever gives me the least pain for the situation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With