JEE7: Using Logging with SLF4j

×

Overview SLf4j logging with jcl-over-slf4j

SLf4j logging with jcl-over-slf4j
Image slf4j_logging_img1.jpg  NOT Found

pom.xml


       <!-- Logging -->
            <dependency>
                <groupId>ch.qos.logback</groupId>
                <artifactId>logback-classic</artifactId>
                <version>1.0.13</version>
            </dependency>
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>jcl-over-slf4j</artifactId>
                <version>1.7.5</version>
            </dependency>

Downloaded External Libraries by MAVEN

  • logback-classic-1.0.13.jar
  • logback-core-1.0.13.jar
  • jcl-over-slf4j-1.7.5.jar
  • slf4j-api-1.7.5.jar

Jee7 Code Sample for SLF4j Logging

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

// The Java class will be hosted at the URI path "/helloworld"
@Path("/helloworld")
public class HelloWorld {
    private static final Logger LOGGER
            = LoggerFactory.getLogger(HelloWorld.class);

    // The Java method will process HTTP GET requests
    @GET
    // The Java method will produce content identified by the MIME Media type "text/plain"
    @Produces("text/html")
    public String getFirstMessage() {
        LOGGER.info(" ---- Inside HTTP GET Request --- ");
 ..
<

SLF4j Logger Output [ server.log payara41\glassfish\domains\domain1\logs ]

  10:43:31.058 [http-thread-pool::http-listener-1(4)] INFO  HelloWorld -  ---- Inside HTTP GET Request --- 

Refrence

Leave a Reply

Your email address will not be published. Required fields are marked *