ayushgp
ayushgp

Reputation: 5091

Log4J logger without appender use

If I have a log4j.xml file that I'm using to init the loggers, with a logger(foo) defined in it without any appender-ref tags within it, what does this logger do? If it does nothing, does it have an impact on performance?

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
  <appender name="console" class="org.apache.log4j.ConsoleAppender"> 
    <param name="Target" value="System.out"/> 
    <layout class="org.apache.log4j.PatternLayout"> 
      <param name="ConversionPattern" value="%-5p %c{1} - %m%n"/> 
    </layout> 
  </appender> 

  <logger name="foo">
    <level value="WARN"/>
  </logger>

  <root> 
    <priority value ="debug" /> 
    <appender-ref ref="console" /> 
  </root>

</log4j:configuration>

Upvotes: 5

Views: 2902

Answers (2)

Gili Garibi
Gili Garibi

Reputation: 426

From the manual: "Each enabled logging request for a given logger will be forwarded to all the appenders in that logger as well as the appenders higher in the hierarchy" So I guess they will inherit from root.

Upvotes: 7

user9181740
user9181740

Reputation:

This logger is adding warning logs and they are generated whenever there is a warning in console program for which this logger config is running, it will add it to logs and yes it will have impacts on performance as we are adding logs only for debug. If you see in xml, priority value is set to debug if it is set to Release then it will log the release mode messages The impact will be huge as we should log errors as well. That is the whole purpose of logger..

Upvotes: 0

Related Questions