What's new? | Help | Directory | Sign in
Google
gwittir
Adding sparkle to GWT
  
  
  
  
    
Search
for
Updated Oct 09, 2007 by kebernet
Labels: Documentation-Intro, Featured
Logging  
An introduction to the Gwittir logging API.

Introduction

GWT includes basic logging, but GWT.log() is only really good for development time logging. When you start building applications, there are times you will need more than this. It also helps to have a logging system that can carry all the way through to the JavaScript so you can capture logging messages from staging and production environments. To that end, Gwittir provides its own logging system.

How it Works

The com.totsp.gwittir.client.log package provides a Logger object that works much like you would expect a Logger to work in other Java-based logging environments. This Logger object will log both to the GWTShell, using the GWT.log() method, and make a call back to the remote /LogService RPC service. The RPC service by default, will pass log messages on to the default context logger ( Servlet.log() ). It will also look for implementations of the com.totsp.gwittir.service.ServerLogService using the standard JAR SPI method. This can be used to pass through these log messages to whatever logging system you wish to use on the server side. Gwittir currently includes a log4j-spi module that logs to Log4J, with more to come.

The logging system also defined a new property: log.level. This is defined for the application in the same way "locale" is for I18N. Either via a <meta> tag in the HTML Host Page, or via a request parameter. Note: This property only defines what messages are sent back to the server, NOT what log level is set on the server. If you have a log.level of "debug" in the client, and a log level of "warn" on the server, you will be sending a whole lot of pointless HTTP requests back to the server, since the server will only capture "warn" or better. This does not apply to standard context logging, but will impact SPI's registered on the server.

Usage

First, you need to inherit the logging module:

   <inherits name="com.totsp.gwittir.Logging"/>

Typical usage would be in the form of:

    private Logger log = Logger.getLogger("com.my.package.log.Name");
   //...

    log.log(Level.WARN, "An exception was thrown!", exception);

A few things to keep in mind:

Using the runtime log level configuration can significantly slow your compile time, as a version must be compiled for each log level. To reduce this, there are specific level module files you can include that will specify the log level at build time, and this cut the compile speed.

To use this, include ONE and ONLY ONE of the following:

   <inherits name="com.totsp.gwittir.LoggingInfo"/> 

for info level or better, or

   <inherits name="com.totsp.gwittir.LoggingWarn"/>

for warn level or better.

Future Considerations


Sign in to add a comment