log4j:WARN No appenders could be found for logger

If you get the following warning in your application after adding log4j.jar inside your application. You should need to put log4j.xml and log4j.dtd in your application’s classpath. (putting these files inside a source folder will  be also worked, it should be in the classpath)

If you use  Netbeans IDE, it is better to create a source folder named log4j for the config files like the one on the following image







log4j:WARN No appenders could be found for logger (org.springframework.context.support.ClassPathXmlApplicationContext).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
BUILD SUCCESSFUL (total time: 1 second)

How to define DailyRollingFileAppender in Log4J.properties file

      Click here to attend Spring Framework 4.x and certification course with a discount

Spring Framework and Core Spring Certification Udemy course with discount
Spring Framework and Core Spring Certification Udemy course with a discount coupon

Use the following Log4j.properties file

# Set root category priority to INFO and its only appender to DailyRollingFileAppender.
log4j.rootCategory=INFO, LOGFILE

# Set the enterprise logger category to FATAL and its only appender to DailyRollingFileAppender.
log4j.logger.org.apache.axis.enterprise=FATAL, LOGFILE

#reFactor Tuna
# LOGFILE is set to be a DailyRollingFileAppender appender using a PatternLayout.
log4j.appender.LOGFILE = org.apache.log4j.DailyRollingFileAppender
log4j.appender.LOGFILE.Append = true
log4j.appender.LOGFILE.DatePattern = ‘.’yyy-MM-dd
log4j.appender.LOGFILE.layout = org.apache.log4j.PatternLayout
log4j.appender.LOGFILE.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss} %c{1} [%p] %m%n

Log4j Log Levels

#Log4j log levels in decreasing order of severity

The FATAL level designates very severe error events that will presumably lead the application to abort.
The ERROR level designates error events that might still allow the application to continue running.
Level WARN
The WARN level designates potentially harmful situations.
Level INFO
The INFO level designates informational messages that highlight the progress of the application at coarse-grained level.
The DEBUG Level designates fine-grained informational events that are most useful to debug an application.
The TRACE Level designates finer-grained informational events than the DEBUG


Level ALL
The ALL has the lowest possible rank and is intended to turn on all logging.
Level OFF
The OFF has the highest possible rank and is intended to turn off logging.


How to use DailyRollingFileAppender in log4j.xml

<appender name=”abcWebServiceDAILY_ROLLING_FILE”
<param name=”File” value=”/mainlog/abcWebService_mainapp.log” />
<param name=”Append” value=”true” />
<param name=”DatePattern” value=”‘.’dd-MM-yyyy” />
<param name=”ConversionPattern”
value=”[%d{ISO8601}] %-5p %m%n” />

<logger name=”com.blabla.abcWebServiceLogger” additivity=”false”>
<level value=”ERROR” />
<appender-ref ref=”abcWebServiceDAILY_ROLLING_FILE” />

If you want to define a DailyRollingFile for your project’s logs, then the configuration above will be worked.
Log files will be named and stored in the following format

abcWebService_mainapp.log –> today you can see the log file in this format