You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by wolverine my <wo...@gmail.com> on 2007/03/16 10:30:24 UTC

How to log message from the parent class

Hi!

I have the following Java classes:


abstract class AbstractAnimal {

  Logger logger = Logger.getLogger(AbstractAnimal.class);

  protected void something() {
    logger.debug("animal is doing something");
  }
}

class Dog extends AbstractAnimal {

  Logger logger = Logger.getLogger(Dog.class);

  protected void anything() {
    logger.debug("dog is doing anything");
    something();
  }
}

class Cat extends AbstractAnimal {

  Logger logger = Logger.getLogger(Cat.class);

  protected void nothing() {
    logger.debug("cat is doing nothing");
    something();
  }
}


Note that the classes are in three difference packages
and the log4j.properties looks like the following:


log4j.logger.Dog=ALL, R1
log4j.appender.R1=org.apache.log4j.DailyRollingFileAppender
log4j.appender.R1.File=dog.log

log4j.logger.Dog=ALL, R2
log4j.appender.R2=org.apache.log4j.DailyRollingFileAppender
log4j.appender.R2.File=cat.log


The above configuration only logs "dog is doing anything" to dog.log
and "cat is doing nothing" to cat.log.

How can I configure Log4j so that it will also log "animal is doing
something" in both log files?

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