Jun 17, 2010

Unifying Slf4j, gwt-log, GWT, AppEngine, Part I

I like the API of SLF4J very much and used in all my code so far.

Can I re-use the same API for code that runs via GWT in the browser?


Experiment:
  • Check out source code from http://github.com/ceki/slf4j from trunk on 2010-06-17
  • Add GWT dependencies in Maven, add get-maven plugin in POM
  • Create a dummy entry point and a get.xml file
  • Run mvn gwt:compile
Result:

[INFO] Compiling module org.slf4j.GWTTest
[INFO]    Validating newly compiled units
[INFO]       [ERROR] Errors in 'file:/O:/2010/slf4j-api/src/main/java/org/slf4j/LoggerFactory.java'
[INFO]          [ERROR] Line 28: The import java.net cannot be resolved
[INFO]          [ERROR] Line 207: The method getClassLoader() is undefined for the type Class
[INFO]          [ERROR] Line 217: URL cannot be resolved to a type
[INFO]          [ERROR] Line 217: URL cannot be resolved to a type
[INFO]       [ERROR] Errors in 'file:/O:/2010/slf4j-api/src/main/java/org/slf4j/helpers/MessageFormatter.java'
[INFO]          [ERROR] Line 27: The import java.text cannot be resolved
[INFO]       [ERROR] Errors in 'file:/O:/2010/slf4j-api/src/main/java/org/slf4j/MDC.java'
[INFO]          [ERROR] Line 74: No source code is available for type java.lang.NoClassDefFoundError; did you forget to inherit a required module?
[INFO]       [ERROR] Errors in 'file:/O:/2010/slf4j-api/src/main/java/org/slf4j/MarkerFactory.java'
[INFO]          [ERROR] Line 53: No source code is available for type java.lang.NoClassDefFoundError; did you forget to inherit a required module?
[INFO]       [ERROR] Errors in 'file:/O:/2010/slf4j-api/src/main/java/org/slf4j/helpers/BasicMDCAdapter.java'
[INFO]          [ERROR] Line 47: No source code is available for type java.lang.InheritableThreadLocal; did you forget to inherit a required module?
[INFO]       [ERROR] Errors in 'file:/O:/2010/slf4j-api/src/main/java/org/slf4j/helpers/NamedLoggerBase.java'
[INFO]          [ERROR] Line 40: No source code is available for type java.io.ObjectStreamException; did you forget to inherit a required module?

These errors show that SLF4j is not GWT-ready by itself. Now there are two options:
  • Create a drop-in replacement that implements some parts differently
  • Create a new SLF4j-like API which IS GWT-ready
The second option is probably less work, but the first option would be easier to use.I'll keep you updated.

No comments:

Post a Comment