A custom logging handler is another way to present logging messages. A custom handler could be used to send logging messages to a web service, write them to disk, send them to window.alert(), or show messages to the users of an application. A custom logging handler, which must implement the abstract Handler.handle() method, is created by extending the jsx3.util.Logger.Handler class or one of its subclasses. This method defines how a logging message is handled. The following implementation, which simply stores a rotating cache of messages in memory, is from the MemoryHandler class: MemoryHandler.prototype.handle = function(objRecord) { this._buffer.push(objRecord); if (this._buffer.length > this._bufferSize) this._buffer.shift(); }; Custom handlers are configured in the logging system configuration file just like other handlers. Since custom handlers load after the logging system has been configured, they must be configured with the attribute lazy="true", so that the logging system won't throw an error on initialization if the handler class isn't loaded. Another option is to use the attribute require="true", so the class is loaded immediately using the dynamic class loading mechanism. After calling the jsx3.lang.Class.defineClass() method to define a custom handler class, if using lazy="true", the jsx3.util.Logger.Handler.registerHandlerClass() method must be called to tell the logging system that the handler class has been defined. For example, jsx3.util.Logger.Handler.registerHandlerClass( com.tibco.LogHandler.jsxclass); Handlers may also define bean-style properties that can be configured in the logging system configuration file. Any property element nested within a handler element defines a name-value pair of a property of the handler. The handler class must have a bean-style setter method for any configurable property. For example, the handler class, FormatHandler, defines the property format, because it defines getFormat() and setFormat() methods. Therefore, any handler of a class that is a descendant of FormatHandler can be configured with the format property. For more information, see jsx3.util.Logger.FormatHandler in General Interface API Reference. |
Contents
|
