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:
- 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!");
}
}
2 Comments
Hi
you trying to log by not decelerated logger
>>@Inject
>> private Logger logger;
>>log.info(“Hello Logger!”);
Oops, a little error during copy-paste… Just rectified it.
Thank you!