Helma Logo
main list history
previous version  overview  next version

Version 3 by hannes on 16. May 2008, 15:26

The *helma.logging module|http://dev.helma.org/trac/helma/browser/helma-ng/trunk/modules/helma/logging.js* provides logging functionality using *Apache log4j|http://logging.apache.org/log4j/1.2/index.html*.

helma.logging can be configured by passing a log4j XML or properties configuration file to the setConfig() method. The default configuration is file *modules/helma/log4j.properties|http://dev.helma.org/trac/helma/browser/helma-ng/trunk/modules/helma/log4j.properties*.

Helma provides a special Appender class called org.helma.util.RhinoAppender that allows to send log messages to a Javascript *callback* function. The logging module provides the methods enableResponseLog() and disableResponseLog() to enable and disable appending of RhinoAppender log messages to a response buffer, using similar formatting as res.debug in Helma 1.

  importModule('helma.logging', 'logging');
  logging.enableResponseLog();
  var log = logging.getLogger('modulename');
  ...
  logThen the following code .info("log message");..

    log.info("Hello world!");
    try {
        foo.bar;
    } catch (e) {
        log.error(e, e.rhinoException);
    }

... will produce the following output on the rendered page:

<div class="helma-debug-line" style="background: #fc3; color: black; border-top: 1px solid black;">3300 [pool-1-thread-2] INFO  main  - Hello world!
</div>
<div class="helma-debug-line" style="background: #fc3; color: black; border-top: 1px solid black;">3303 [pool-1-thread-2] ERROR main  - ReferenceError: "foo" is not defined.
<h3>Script Stack</h3>
<javascript stack trace>
<h3>Java Stack</h3>
<java stack trace>
</div>

     removed
     added