Open In App
Related Articles

Hibernate – Logging By Log4j Using Properties File

Improve Article
Save Article
Like 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.

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 26 Apr, 2022
Like Article
Save Article
Similar Reads
Complete Tutorials