My favorites | Sign in
Project Home Wiki Issues Source
Search
for
XydraLog  
Unified logging on GWT, plain Java, and AppEngine (GAE/J)
Featured, Phase-Deploy
Updated Jul 9, 2011 by max.at.x...@gmail.com

The holy grail of most code in Xydra is simple portability between plain Java, AppEngine and usage via GWT as JavaScript in the browser. Until now, there was no logging framework being able to do that.


UPDATE: It looks like GWT 2.1 brings java.util.logging which also works on GAE
The XydraLog mimics the SLF4j API, although only the very easy parts. At runtime, it re-uses the great gwt-log project, if running in GWT. In fact, if you use GWT, you must use gwt-log as well -- or get a nasty error from XydraLog.

Usage

Maven dependency:

<dependency>
  <groupId>org.xydra</groupId>
  <artifactId>log</artifactId>
  <version>0.0.1</version>
</dependency>

Configuration in GWT projects

For your GWT projects also add:

<dependency>
  <groupId>com.google.code.gwt-log</groupId>
  <artifactId>gwt-log</artifactId>
  <version>2.6.2</version>
</dependency>

In the module add

<!--  Import the log module -->
<inherits name='org.xydra.log.Xlog' />

Also add one of the configs described at http://code.google.com/p/gwt-log/wiki/GettingStarted -- e.g. this one:

<!-- Import the gwt-log -->
<inherits name="com.allen_sauer.gwt.log.gwt-log-OFF" />
<extend-property name="log_level" values="INFO" />

Using the logger

In a class Person use

private static final Logger log = LoggerFactory.getLogger(Person.class);

And in methods use

log.trace( ... );
log.trace( ..., exception );
log.debug, log.info, log.warn, log.error

if(log.isTraceEnabled()) {
  // construct a complex string and log it
}

Sample Code

A sample project using XydraLog in a GWT project can be found here in our SVN

For Developers

The full source code is in this svn at /trunk/org.xydra.log

Features

  • Almost a drop-in replacement for the very basic SLF4j API -- you just need to change imports
  • Built-in logger output implementation with verbose defaults (log level, source class, method name, line number, message, throwable message)

Roadmap / Not-Yet-Features

  • Delegate on the server/java side to slf4j or java.util.logging (for appengine)

Sign in to add a comment
Powered by Google Project Hosting