JBoss.orgCommunity Documentation

Chapter 13. Logging

13.1. What is slf4j?
13.2. Client-Side Setup
13.2.1. Errai Client-Side Log Handlers
13.2.2. Configuring Errai Client-Side Log Handlers
13.2.3. Format String
13.3. Server-Side Setup
13.4. Example Usage
13.5. Logger Names

Errai now supports using the slf4j logging api on the server and client. This gives you the flexibility of choosing your own logging back-end for your server-side code, while still allowing a uniform logging interface that can be used in shared packages.

sl4j is logging abstraction. Using the slf4j api, you can add log statements to your code using a fixed api while maintaining the ability to switch the logging implementation at run-time. For example, the slf4j api can be used with java.util.logging (JUL) as the back-end.

The client-side slf4j code uses the ��� GWT Logging as the back-end. Using slf4j in client-side code has two steps:

  1. Add the errai-common artifact as a maven dependency to your project
  2. Inherit the gwt module org.jboss.errai.common.ErraiCommon

Log handler levels can be changed at run-time through Java or Javascript. To do so through Java, use the LoggingHandlerConfigurator in Errai Common. Here’s an example:


Each handler has a native Javascript variable associated with its log level:

HandlerVariable Name

ErraiSystemLogHandler

erraiSystemLogHandlerLevel

ErraiConsoleLogHandler

erraiConsoleLogHandlerLevel

ErraiDevelopmentModeLogHandler

erraiDevelopmentModeLogHandlerLevel

ErraiFirebugLogHandler

erraiFirebugLogHandlerLevel

Since these are native Javascript variables, they can easily be set in a script tag on your host page:


<script type="text/javascript">
  erraiSystemLoghandlerLevel = "INFO";
</script>

The possible log levels correspond to those in java.util.logging.Level .

On the server you are free to use any logging back-end that has slf4j bindings (or to make your own). Just make sure to add dependencies for the slf4j-api artifact and the slf4j binding you choose. Note: Some application servers provide their own slf4j bindings (such as JBoss AS), in which case you should add your binding dependency as provided scope.

To learn more about how to setup slf4j for your server-side code, see their website .

Here is sample usage of the slf4j code (which with the above setup can be run on the client or server):


By default, the above example with provide a logger with the fully qualified class name of the enclosing class. To inject a logger with an alternate name, use the NamedLogger annotation: