go to  ForumEasy.com   
JavaPro
Home » Archive » Message


[Email To Friend][View in Live Context][prev topic « prev post | next post » next topic]
  Simple Example SLF4j + Log4j
 
Subject: Simple Example SLF4j + Log4j
Author: EricJ
Posted on: 09/07/2013 06:14:07 AM

SLF4J stands for Simple Logging Facade for Java which is an abstract layer of different logging frameworks. This make the code more reusable given that the real logging implementation can be plugged-in at end user's desire.

In this example, Log4j is chosen as the real logging framework.

What are required?

1) Abstraction -- slf4j-api-x.jar

2) Adapter -- slf4j-log4j-x.jar

3) The real framework -- log4j-x.jar



Code Example:

package com.mycompany.example;

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

public class SLF4j {
	
    /** debug logger reference. */
    private static Logger logger = LoggerFactory.getLogger(SLF4j.class);
	
    public void hello(String name){
        logger.error("Hello {}!", name);
        logger.warn ("Hello {}!", name);
        logger.info ("Hello {}!", name);
        logger.debug("Hello {}!", name);
        logger.trace("Hello {}!", name);
    }

    public static void main(String[] args){
        SLF4j slf4j = new SLF4j();
        slf4j.hello("World");		
		
    }

}


Replies:


References:

 


 
Powered by ForumEasy © 2002-2022, All Rights Reserved. | Privacy Policy | Terms of Use
 
Get your own forum today. It's easy and free.