118
Hibernate Logging by Log4j using xml file
Logging enables the programmer to write the log details into a file permanently. Log4j and Logback frameworks can be used in hibernate framework to support logging.
There are two ways to perform logging using log4j:
- By log4j.xml file (or)
- By log4j.properties file
Levels of Logging
Following are the common logging levels.
Levels | Description |
---|---|
OFF | This level is used to turn off logging. |
WARNING | This is a message level that indicates a problem. |
SEVERE | This is a message level that indicates a failure. |
INFO | This level is used for informational messages. |
CONFIG | This level is used for static configuration messages. |
Steps to perform Hibernate Logging by Log4j using xml file
There are two ways to perform logging using log4j using xml file:
- Load the log4j jar files with hibernate
- Create the log4j.xml file inside the src folder (parallel with hibernate.cfg.xml file)
Example of Hibernate Logging by Log4j using xml file
You can enable logging in hibernate by following only two steps in any hibernate example. This is the first example of hibernate application with logging support using log4j.
Load the required jar files
You need to load the slf4j.jar and log4j.jar files with hibernate jar files.
download all the required jar files
Create log4j.xml file
Now you need to create log4j.xml file. In this example, all the log details will be written in the C:/tutoraspirelog.log file.
log4j.xml