logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jens Gruentjes" <jens.gruent...@ebira.de>
Subject Re: Problems with inheritance of com.foo... loggers
Date Thu, 04 Feb 2010 14:36:09 GMT
Hi Douglas,

thanks for your answer which helped me save a lot of time. Your  
explanation is evident but I did not realize that for myself.
-- 
Kind regards
Jens


Zitat von "Douglas E Wegscheid" <Douglas_E_Wegscheid@whirlpool.com>:

> "de.wota.segmentation.Bar" will inherit from "de.wota.segmentation",
> "de.wota", and "de" but not "de.wota.MyApp".
>
> Change your configuration to set up logging for "de.wota" instead of
> "de.wota.MyApp".
>
> Douglas E Wegscheid
> Lead Technical Analyst, Whirlpool Corporation
> (269)-923-5278
>
> "A wrong note played hesitatingly is a wrong note. A wrong note played
> with conviction is interpretation."
>
>
>
> "Jens Gruentjes" <jens.gruentjes@ebira.de> wrote on 02/04/2010 02:57:10
> AM:
>
>> 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:
>>
>> jens@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.
>> jens@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-unsubscribe@logging.apache.org
>> For additional commands, e-mail: log4j-user-help@logging.apache.org
>>
>


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


Mime
View raw message