via Hibernate Logging Configuration – SLF4J + Log4j and Logback | Examples Java Code Geeks.
In this example we are going to see how to configure Logging in Hibernate.SLF4J (Simple Logging Facade for Java) is a very nice logging framwork that Hibernate uses, in order to output your logs using your favorite logging tool ( log4j, JCL, JDK logging, logback) to your preferd location. We are going to use SLF4J along with log4j and Logback.
So these are the tools we are going to use on a Windows 7 platform:
- JDK 1.7
- Maven 3.0.5
- Hibernate 4.2.3.Final
- MySQL JDBC driver 5.1.9
- Eclipse 4.3 Kepler
The basis of this tutorials is going to be this Eclipse project: HibernateMySQLExample.zip
via Maven SLF4J integration example.
In this example, we shall show you how to integrate Apache Maven with SLF4J. Apache Maven is a software project management and comprehension tool. It provides powerful features like superior dependency management including automatic updating and transitive dependencies.
It follows the principle of convention over configuration, due to which one can start with a minimal configuration and sensible defaults will be provided for all the missing configuration.
Maven uses central repositories where various artifacts like JAR files can be hosted. It comes with a mechanism that resolves all project dependencies from these central repositories. So effectively you are resolved from keeping and providing JAR files on your project’s classpath.
Maven only needs a file called ‘pom.xml’ where one can define dependencies as we will be seeing in the example below. Once you choose to build the project, these dependencies will be automatically fetched from central repository and put on your application’s classpath.
SLF4J is a simple facade over various logging frameworks. It gives abstraction and therefore makes it easier to change logging implementations later on in a software project.It is a very stable library and is actively used by various open source software like Apache Camel, ActiveMQ, Solr and EhCache etc. For this example we will be using Apache Maven 3.2.5 and SLF4J 1.7.5. The example is compilable on Java 5 and above.