Skip to content
Related Articles

Related Articles

Hibernate – Logging By Log4j Using Properties File

View Discussion
Improve Article
Save Article
  • Last Updated : 26 Apr, 2022
View Discussion
Improve Article
Save Article

Apache log4j is a java-based logging utility. Apache log4j role is to log information to help applications run smoothly, determine what’s happening, and debug processes when errors occur. log4j may logs login attempts (username, password), submission form, and HTTP headers (user-agent, x-forwarded-host, etc.) into the log file or database. Apache log4j 2.0 introduces

  • New plugin system
  • Support for properties
  • Support JSON base configuration
  • Automatic reloading its configuration

Logging in hibernate is done by using log4j. And we have two ways to retrieve logging using log4j. They are as follows 

  1. Logging using log4j by log4j.xml
  2. Logging using log4j by file

In this article, we are going to enable logging using log4j through the properties file.

Logging using log4j by the file

Follow these steps to enable logging using log4j through the properties file. 

  1. You can load the required jar files of log4j with hibernate jar files. 
  2. You need to load the slf4j.jar and log4j.jar files with hibernate jar files.

or the other way is to create a file

  1. You need to create file. 

This is an example image of the file

example image of the file



# initialize root logger with level ERROR for stdout and fout

# set the log level for these components

# add a ConsoleAppender to the logger stdout to write to the console

# use a simple message format
# add a FileAppender to the logger fout

# create a log file

# use a more detailed message pattern

Both are good ways of practice to have logs by log4j. Mostly file along with hibernate-config.xml files are used to create user wanted logs. These logs are very helpful for tracing the errors and finding the process and endpoints that the code is touching while the process of execution.

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!