Recommended Registrar for Use with Java, Hibernate, and Spring

My web application uses an implementation of Java, Hibernate JPA (EntityManager), and Spring. What are my registration options and what do you recommend. Ideally, the configuration would be simple (one configuration file for Hibernate, Spring and my code).

+6
java spring logging hibernate jpa
source share
6 answers

When creating applications from various frameworks, you often need to wrap existing logs, be it log4j or JUL or JULI or something else. The standard application for this is the Simple Logging Facade for Java (SLF4J) . Even if your application does not require SLF4J, now you may want to add a library that needs it, and this is the best hope for a single configuration file in the end.

With that in mind, you should stick with the logging packages supported by SLF4J, but usually it comes down to java.util.logging (JUL) or Apache log4j. This has been a topic of discussion for some time, and you can find many opinions on both sides.

Personally, I find it sad that the Java log is in this situation , and I will use what gives me the least pain for this situation.

+13
source share

log4j is the standard logger that I use. You can configure logging levels and log files by package, so Hibernate, Spring, and your code can go into their own log files.

+7
source share

No one was fired for choosing log4j.

Also check out slf4j.

+5
source share

Hibernate already relies on SLF4J. If I am mistaken, the current version of Spring is based on logging, but SLF4J will be used in the next version. In any case, you can consolidate all logging through SLF4J (see jcl-over-slf4j.jar). Once this is done, you can choose any of java.util.logging, log4j or logback as the basic logging structure.

+4
source share

I use the Apache Commons Logging api with the log4j configuration file (the log4j configuration file is simple, easy for a beginner to understand, and has many examples to work with.

I prefer to use the community registration API because its agnostic about its configuration file. It can be configured through file formats for any number of popular logging packages.

Here is a simple log4j installation that will print out debugging information for your own packages, the INFO level for spring and sleep mode, and WARN for everything else:

# Global logging configuration log4j.rootLogger=WARN, stdout log4j.category.org.mydomain.org=DEBUG log4j.category.org.hibernate=INFO log4j.category.org.springframework=INFO # CONSOLE appender not used by default log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%d %-5p [%t] %c - %m%n 
+3
source share

Generally speaking, Commons Logging is not required and is not suitable for web applications (and stand-alone applications). Good letter about why:

Think Again Before Using the Public Post Registration API

Error in Commons Logging

+1
source share

All Articles