Enable Weld Logging on Glassfish with Maven

Just figured out how to use a Weld-injected Logger on Glassfish.
Unfortunately, i couldn’t get Log4J12 as SL4J Implementation running, like the author of this post did (i hope i’ll find out later), but with the sl4j-jdk14 binding, the logging just works.

Steps:

  1. Add the following dependencies to the pom.xml:
<!-- SL4J API -->
 <dependency>
 <groupId>org.slf4j</groupId>
 <artifactId>slf4j-api</artifactId>
 <version>1.6.0</version>
 </dependency>

 <!-- SLF4J JDK14 Binding  -->
 <dependency>
 <groupId>org.slf4j</groupId>
 <artifactId>slf4j-jdk14</artifactId>
 <version>1.6.0</version>
 </dependency>

 <!-- Injectable Weld-Logger -->
 <dependency>
 <groupId>org.jboss.weld</groupId>
 <artifactId>weld-logger</artifactId>
 <version>1.0.0-CR2</version>
 </dependency>

2. Inject the Logger and use it as usual:

import javax.inject.Inject;
import org.slf4j.Logger;

public class Example {
  @Inject
  private Logger logger;

  public void exampleFunc() {
    logger.info("Hello Logger!");
  }
}
This entry was posted in General and tagged , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

2 Comments

  1. kislo_metal
    Posted 31. May 2010 at 14:54 | Permalink

    Hi
    you trying to log by not decelerated logger
    >>@Inject
    >> private Logger logger;

    >>log.info(“Hello Logger!”);

  2. ingo
    Posted 31. May 2010 at 17:50 | Permalink

    Oops, a little error during copy-paste… Just rectified it.
    Thank you!

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>