JEE7: Using Logging with SLF4j


Generic SLF4l Logging Overview

Overview SLf4j logging with jcl-over-slf4j

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


       <!-- Logging -->

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"
public class HelloWorld {
    private static final Logger LOGGER
            = LoggerFactory.getLogger(HelloWorld.class);

    // The Java method will process HTTP GET requests
    // The Java method will produce content identified by the MIME Media type "text/plain"
    public String getFirstMessage() {" ---- 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 --- 

JSF accessing an Resource

  • #{status} translates to enum value: FEMALE
  • {backend[status] translates to backend[FEMALE]
  • translates FEMALE to Frau

 <f:selectItem itemValue="#{null}" itemLabel="Auswahl Geschlecht" noSelectionOption="true"  itemDisabled="true" />

Runtime Logging for SLFj/Logback

Display all Classes which are avaiable for Logging via Logback

      LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
      List loggerList = loggerContext.getLoggerList(); -> System.out.println(tmpLogger.toString()
                + "  Log Level:" + tmpLogger.getLevel() + "  Name:" + tmpLogger.getName() ));

An Arquillian Sample using @BeforeClass @AfterClass Annotations

    public static void setUpClass() {
        LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
        ch.qos.logback.classic.Logger myClassLogger =  loggerContext.getLogger("");

    public static void tearDownClass() {
        LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
        ch.qos.logback.classic.Logger myClassLogger =  loggerContext.getLogger("");

    public void testRemoveAccounts()   {


Leave a Reply

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