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 Sébastien Hiblot <se...@atosorigin.com> on 2003/01/16 14:22:03 UTC

Help !

Hi,

We're working on a java web site and we'd like to use log4j in order
to log the error.

We have made a class to implement the init of log4j. Here the source of this
class :

private Logger logger ;

public Trace(String class_name) {
	logger = LogManager.getLogger(class_name);
      Layout layout = new PatternLayout("%d{yyyyMMdd-HH:mm:ss} %m%n");
      logger.addAppender(new ConsoleAppender(layout,
ConsoleAppender.SYSTEM_OUT));
      logger.setLevel(Level.DEBUG);
      try {
      	logger.addAppender(new FileAppender(layout, (String)
Ecx_constants.getInstance().get("log4j_fileTrace"), true));
      } catch (IOException e) {
}

To log something :
Trace t = new Trace(this.getClass().toString()) ;
t.debug("My message");

The first time, we call the page, the log contain the good thing :
20030116-12:00:00 My message

But the second time we call the page, 30 sec after, we have in the log:
20030116-12:00:00 My message
20030116-12:00:30 My message
20030116-12:00:30 My message

==> the log appears 2 times !
the third time, the log appears 3 time, etc......

Can you help us please ?

Thx


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Help !

Posted by Neil Pitman <ne...@sympatico.ca>.
Bonjour Sébastien

I'm new to log4J as well, but what you're doing seems very complicated.  Why
do you do all the configuration in java code?  I do it all in the config
file.

My code looks instance like:

public class GererPage extends Action {

static Logger logger = Logger.getLogger(GererPage.class.getName());

public GererPage() {

logger.debug("creating new GererPage -" + this.toString());

}

bla,bla bla

}

I also have once in my application:

void init() {

    PropertyConfigurator.configure("myfile.lcf");

}

This works fine to log messages.  I haven't figured out whether you are
trying to do something else in your trace function.



Bonne chance,



Neil

----- Original Message -----
From: "Sébastien Hiblot" <se...@atosorigin.com>
To: <lo...@jakarta.apache.org>
Sent: Thursday, January 16, 2003 8:22 AM
Subject: Help !


> Hi,
>
> We're working on a java web site and we'd like to use log4j in order
> to log the error.
>
> We have made a class to implement the init of log4j. Here the source of
this
> class :
>
> private Logger logger ;
>
> public Trace(String class_name) {
> logger = LogManager.getLogger(class_name);
>       Layout layout = new PatternLayout("%d{yyyyMMdd-HH:mm:ss} %m%n");
>       logger.addAppender(new ConsoleAppender(layout,
> ConsoleAppender.SYSTEM_OUT));
>       logger.setLevel(Level.DEBUG);
>       try {
>       logger.addAppender(new FileAppender(layout, (String)
> Ecx_constants.getInstance().get("log4j_fileTrace"), true));
>       } catch (IOException e) {
> }
>
> To log something :
> Trace t = new Trace(this.getClass().toString()) ;
> t.debug("My message");
>
> The first time, we call the page, the log contain the good thing :
> 20030116-12:00:00 My message
>
> But the second time we call the page, 30 sec after, we have in the log:
> 20030116-12:00:00 My message
> 20030116-12:00:30 My message
> 20030116-12:00:30 My message
>
> ==> the log appears 2 times !
> the third time, the log appears 3 time, etc......
>
> Can you help us please ?
>
> Thx
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>