Wednesday, November 16th, 2005
log4js: Logging in JavaScript
<>p>Stephan Strittmatter has written about adopting Log4J in JavaScript, and came up with log4js.There are already three appenders to get the output of logging:
- Write out the logs to a additional popup window in browser with
WindowAppender. - I was also inspired by Dan Allen Logging via Meta and added an appender using his idea to add logging to meta with
MetatagAppender. - Default is
DummyAppender, which is doing nothing. If you do not set an specific appender, this one is used and nothing is logged. This makes it easy to disable logging by juest commenting out the setAppender() line in your scripts.
Example Code
<!-- first import log4js in your page --> <script src="log4js" type="text/javascript" /> [...] //create an Logger and set the wanted LogLevel on constructer var log = new Logger(LogLevel.TRACE); //to log to separate log window set appender to WindowAppender log.setAppender(new WindowAppender()); [...] //then you can call the log within your page log.trace( "trace me" ); log.debug( "also debug" );
Related Content:











I’ve added the ability to log to multiple appenders and also added two new appenders to Stephan’s code:
-FileAppender – logs to a text file
-WindowsEventAppender – logs to windows event log
More info here:
http://issues.apache.org/bugzilla/show_bug.cgi?id=36961
ç ”ç©¶ç ”ç©¶