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 Bruno Le Tual <br...@groupe-asten.fr> on 2005/12/29 00:24:44 UTC

Dispatch messages to multiple files from the same class with several loggers ?

Hi,

is it possible ?

package chapter1;
import org.apache.log4j.Logger;
public class HelloWorld1
{
  static Logger logger1 = Logger.getLogger("something");
  static Logger logger2 = Logger.getLogger("something else");
  static Logger logger3 = Logger.getLogger("something else else");
  static Logger logger4 = Logger.getLogger("something else else else");

  static public void main(String[] args)
  {
    // TODO, some loggers init stuff ???? HOW ?
    // ... and finally :
    logger1.info("Hello world. 1");
    logger2.info("Hello world. 2");
    logger3.info("Hello world. 3");
    logger4.info("Hello world. 4");
  }
}

I would like to output these logger messages in 4 files.

file1.log --> "Hello world. 1"
file2.log --> "Hello world. 2"
file3.log --> "Hello world. 3"
file4.log --> "Hello world. 4"


I would like also to rename "fileX.log" at runtime and not just configure
them in log4j.properties
or log4j.xml.


IS IT POSSIBLE from one class to instantiate several loggers to dispatch
messages in differents files?
(Without duplicating messages and for ALL levels : info, warn, error ...)

I googled for a long time but I did not find a good answer ....


Thanks a lot,


 Bruno.


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