Wednesday 24 March 2010

GWT Logging

Have recently started working with GWT and although by no means expert, see absolutely that this is the way web applications will be being developed in the future to create feature rich, testable web UI's.

The first thing I found when developing the client UI was that it was quite difficult to see what was going on from a logging perspective so after a quick look, I found gwt-log which solves this issue.

I have been using the Eclipse plugins to create my base projects and it all runs quite nicely and seamlessly. So if you would like to have client side logging ability do the following.

Dependencies
1. gwt-log

This is the entry point and core logging implementation. It has two other dependencies

2. commons-logging-1.1.jar
3. log4j-1.2.15.jar

Place these jars in the classpath of your gwt application, which in a Eclipse generated GWT project would be /war/WEB-INF/lib.

Once you have done this there are some configurations you will need to add, namely registering it in the *.gwt.xml file and adding a servlet mapping.

So in your *.gwt.xml file add the following lines

The import declaration
<inherits name="com.allen_sauer.gwt.log.gwt-log-OFF">

Your log levels
<extend-property name="log_level" values="INFO">
<set-property name="log_level" value="INFO">

This setting will cause the output to appear in the hosted mode console
<set-property name="log_DivLogger" value="DISABLED"></set-property>


Then in your web.xml file add the servlet mapping


<servlet>
<servlet-name>remoteLoggerServiceImpl</servlet-name>
<servlet-class>com.allen_sauer.gwt.log.server.RemoteLoggerServiceImpl</servlet-class></servlet>
<servlet-mapping>
<servlet-name>remoteLoggerServiceImpl</servlet-name>
<url-pattern>/[Application url]/gwt-log</url-pattern>
</servlet-mapping>



Once this is done within your GWT client module you can reference the logger via the static methods
in the com.allen_sauer.gwt.log.client.Log class and your logging output will look something like this. Very handy when sifting through what events have been fired when and for what reason.

.



No comments: