Hello to all readers,

I am new to log4j and I encounter several problems which are maybe caused by my limited understanding fo log4j.

I have a simple setup with two classes (de.wota.MyApp and de.wota.segmentation.Bar) and an xml configuration file for log4j. I thought that the logger defined in Bar.java inherits its level and most of all its appender(s) from the logger defined in MyApp.java. But despite reading the manuals and the list archives I always get the following error when I execute MyApp:

j...@jensen ~/Java/wota_rw $ java de.wota.MyApp
log4j: reset attribute= "false".
log4j: Threshold ="null".
log4j: Retreiving an instance of org.apache.log4j.Logger.
log4j: Setting [de.wota.MyApp] additivity to [true].
log4j: Level value for de.wota.MyApp is  [DEBUG].
log4j: de.wota.MyApp level set to DEBUG
log4j: Class name: [org.apache.log4j.ConsoleAppender]
log4j: Setting property [target] to [System.out].
log4j: Setting property [threshold] to [INFO].
log4j: Parsing layout of class: "org.apache.log4j.PatternLayout"
log4j: Setting property [conversionPattern] to [%8r %p %c %x - %m%n].
log4j: Adding appender named [console] to category [de.wota.MyApp].
       0 INFO de.wota.MyApp  - Entering application.
log4j:WARN No appenders could be found for logger (de.wota.segmentation.Bar).
log4j:WARN Please initialize the log4j system properly.
Parent is root
       1 INFO de.wota.MyApp  - Exiting application.
j...@jensen ~/Java/wota_rw $

What I expected to see was the output from Bar.java which is missing here. I wanted to know who is the parent of the logger in Bar.java is and it turned out to be root. I thought that this should be the logger from MyApp.java. Can someone tell me what I misunderstand? I am a little confused. The code follows below.

Thanks for your explanations and your help!


This is MyApp.java:

package de.wota;

import org.apache.log4j.Logger;
import org.apache.log4j.xml.DOMConfigurator;

import de.wota.segmentation.Bar;

public class MyApp {
    // Define a static logger variable so that it references the
    // Logger instance named "MyApp".
    static Logger logger = Logger.getLogger(MyApp.class);

    public static void main(String[] args) {

        // Set up an xml configuration that logs on the console.
        DOMConfigurator.configureAndWatch("config_log.xml");

        logger.info("Entering application.");
        Bar bar = new Bar();
        bar.doIt();
        logger.info("Exiting application.");
    }
}

This is Bar.java:

package de.wota.segmentation;

import org.apache.log4j.Logger;

public class Bar {
    static Logger logger = Logger.getLogger(Bar.class);

    public void doIt() {
      logger.debug("Did it again!");
      System.out.println("Parent is "+logger.getParent().getName());
    }

}

And finally config_log.xml

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

<log4j:configuration debug="true" xmlns:log4j="http://jakarta.apache.org/log4j/";>

  <appender name="console" class="org.apache.log4j.ConsoleAppender">
    <param name="Target" value="System.out"/>
    <param name="threshold" value="info" />
    <layout class="org.apache.log4j.PatternLayout">
      <param name="ConversionPattern" value="%8r %p %c %x - %m%n"/>
    </layout>
  </appender>

  <logger name="de.wota.MyApp">
    <level value="DEBUG" />
    <appender-ref ref="console" />
  </logger>

</log4j:configuration>

--
Kind regards
Jens



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
For additional commands, e-mail: log4j-user-h...@logging.apache.org

Reply via email to