0

Hi I am using logger file in my application as mentioned below and it is logging contents in console and log file perfectly. But still while launching the application it is showing warning "WARN No appenders could be found for logger". The only difference in my case is the xml name is logger.xml.

Why i am getting this warning even the xml is correct and logging all stuff in console as well in file. If i make the copy of same logger.xml file and name it log4j.xml, application did not show any warning.

Is it really require to name logger.xml as log4j.xml or log4j.properties?

<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">

    <appender name="Standard" class="org.apache.log4j.RollingFileAppender">
            <param name="file" value="../classes/test.log"/>
            <param name="Append" value="true"/>
            <param name="maxFileSize" value="2097152"/> <!-- maximum filesize in bytes -->
            <param name="maxBackupIndex" value="1"/> <!-- number of backup files -->
            <layout class="org.apache.log4j.PatternLayout">
                    <param name="ConversionPattern" value="[%-6p] %d{yyyy/MM/dd HH:mm:ss} [%t] %c.%M(): %m%n"/>
            </layout>
    </appender>

    <appender name="Console" class="org.apache.log4j.ConsoleAppender">
            <layout class="org.apache.log4j.PatternLayout">
                    <param name="ConversionPattern" value="[%-6p] %c.%M :  %m%n"/>
            </layout>
    </appender>

    <root>
            <!-- possible values of priority: "DEBUG", "INFO", "WARN", "ERROR" -->
            <priority value="ERROR" />
            <appender-ref ref="Standard"/>
            <appender-ref ref="Console"/>
    </root>
</log4j:configuration>
Gaurav
  • 319
  • 3
  • 20
  • Possible duplicate question - http://stackoverflow.com/questions/12532339/no-appenders-could-be-found-for-loggerlog4j –  May 22 '14 at 14:23

1 Answers1

1

Log4j has a dedicated way in how it searches for the logfile. The detailed process is documented in the documentation.

To cut things short, if you want to use a different file, you need to set it in the log4j.configurationFile system property.

SirRichie
  • 1,176
  • 9
  • 14
  • No, this is not the case, it is finding the provided xml file correctly as all log messages are logged in to provided log file in the xml as well if i delete the xml file from project, it throws error that xml file not found. So log4j is recognizing the log file but i am not sure whether log4j forces user to use the same name for xml and it can not be customized – Gaurav May 22 '14 at 18:20
  • Sorry, misinterpreted your question then. I updated my answer, which I hope helps. – SirRichie Nov 18 '14 at 17:36