log4js ConsoleAppender initialization

Posted by perrierism on Stack Overflow See other posts from Stack Overflow or by perrierism
Published on 2010-05-07T20:08:36Z Indexed on 2010/05/07 20:18 UTC
Read the original article Hit count: 315

I'm wondering if anyone happens to have some experience using Log4js? It seems its normal ConsoleAppender isn't always ready to use immediately after it's added to a logger object... If I have two sequential script tags in a document like:

//Initialize logger
<script type="text/javascript">                   
      var logger = new Log4js.getLogger("JSLOG");
      logger.addAppender(new Log4js.ConsoleAppender(logger, false));
      logger.setLevel(Log4js.Level.INFO);         
</script>


//Use logger
<script type="text/javascript">
     logger.info('Test test');
</script>

... It causes the console pop-up (pop-up window) to appear with an error message on page load:

12:58:23 PM WARN Log4js - Could not run the listener function () {
    return fn.apply(object, arguments);
}. 
TypeError: this.outputElement is null

The console is still initialised, it's there afterward, but for just that first logger call it doesn't seem to be there fully. If I make the first logger call setTimeout("logger.info('test test')", 1000), it doesn't have the error. So it's like it's not ready immediately. Anyone see this before or know what a workaround might be?

Cheers

© Stack Overflow or respective owner

Related posts about log4js

Related posts about JavaScript