Friday, April 10, 2009

Getting gwt-log to 'just work' on Google App Engine

I had a few key goals in mind when I set out on my gwt-log project:
  • Make it extremely easy to include debug logging in GWT client code
  • Log.debug("This is a 'DEBUG' test message");
    Log.info("This is a 'INFO' test message");
    Log.warn("This is a 'WARN' test message");
    Log.error("This is a 'ERROR' test message");
    Log.fatal("This is a 'FATAL' test message");
    
  • Ensure there's zero overhead for production deployments by way of GWT compiler's dead-code elimination

Other goals were added along the way:
  • Provide wide variety of logging destination for client code; today there's console logging, stdout, GWT hosted mode error window, a floating DIV and ...
  • Allow client side log message to be seen on the server; this is particularly useful for mobile web app development (Android, iPhone, etc.); this is provided by the remote logger which utilizes GWT RPC to relay client side messages to the server
  • Provide custom log message formats; a custom formatter is assembled at compile time thanks to GWT generators
  • Allow the same logging statement to be used on both the client and server so that domain model objects can include logging which produce useful results on both tiers

I'm a big fan of Apache log4j so with this last requirement I wanted log messages to use log4j logging when the log4j implementation jar is present on the server. Not everyone loves log4j as much as I do so I wanted to  provide java.util.logging support as a fallback.

Since gwt-log has supported java.util.logging for quite some time I expected it to just work on Google App Engine. Unfortunately, there was a slight snag, which is that java.util.logging.ConsoleHandler is not listed in the JRE Class Whitelist. The Google Plugin for Eclipse does warn me at compile time which is very nice:
java.util.logging.ConsoleHandler is not supported by Google App Engine's Java runtime environment


If I were to ignore this warning, and deploy my app to the cloud anyway I would end up with an exception in the App Engine console Logs view for my app id:

javax.servlet.ServletContext log: Exception while dispatching incoming RPC call
com.google.gwt.user.server.rpc.UnexpectedException: Service method '......' threw an unexpected exception: java.lang.NoClassDefFoundError: java.util.logging.ConsoleHandler is a restricted class. Please see the Google App Engine developer's guide for more details.


The fix was straight forward enough: just get rid of the offending lines of code which some in the community disliked anyway.

With that fix in place, gwt-log is humming along again with both client side and server side messages appearing in the App Engine console:



To learn more about gwt-log visit the gwt-log home page or the getting started wiki.


Happy logging.
Post a Comment