2 Minutes To Code (β Version)

Log4j - 2 minute tutorial

File Logging : How to configure log4j to write logs in a file using log4j.properties

The log4j.properties file given below will create a log file named example.log in the folder d:/logs.

If you are using log4j-1.2.11 or earlier, make sure that the folder d:/logs is already present as log4j will not create it. From version log4j-1.2.12 onwards , log4j itself will create the log folder if not already present.

The conversion pattern specified is %d [%t] %-5p (%F:%L) - %m%n
%d stands for current timestamp.
%t stands for java thread name.
%p stands for log level.
%F stands for name of class that logged the message.
%L stands for line number where the message is logged.
%m stands for the logged message string
%n stands for new line character