Tuesday 23 June 2015

Slf4j with log4j2 Example.

What is slf4j :- The Simple Logging Facade for Java (SLF4J) serves as a simple facade or abstraction for various logging frameworks (e.g. java.util.logging, logback, log4j) allowing the end user to plug in the desired logging framework at deployment time.Here we are using log4j2 logging framework at deployment time for this we need to add below jars.

Now create java class with slf4j logger object.
Test.java
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Test {
private static final Logger logger = LoggerFactory.getLogger(Test.class);
public static void main(String[] args) {
               logger.debug("this is debug msg");
               logger.info("this is info mesg");
      
}
}

Now where we have to store logs and which pattern we have to print logs these are all configure in log4j2.xml
log4j2.xml
<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
  <Appenders>
    <Console name="STDOUT" target="SYSTEM_OUT">
        <PatternLayout pattern="current date-%d LEVEL-%-5p  Thread-[%t]  Method-%M()   Class name-%C   Message-%m%n"/>
    </Console>
  </Appenders>
   <loggers>
  <Logger name="org.apache.log4j.xml" level="all"/>
    <root level="all">
      <appender-ref ref="STDOUT"/>
    </root>
  </loggers>
</Configuration>


Note: the configuration file log4j2.xml put in class path means under src folder.

32 comments:

  1. It is nice blog Thank you porovide important information and i am searching for same information to save my time Ruby on Rails Online Training Hyderabad


    ReplyDelete
  2. I found your blog while searching for the updates, I am happy to be here. Very useful content and also easily understandable providing.. Believe me I did wrote an post about tutorials for beginners with reference of your blog. 
    best rpa training in bangalore
    rpa training in bangalore
    rpa course in bangalore
    RPA training in bangalore
    rpa training in chennai
    rpa online training

    ReplyDelete
  3. Great Article… I love to read your articles because your writing style is too good, its is very very helpful for all of us and I never get bored while reading your article because, they are becomes a more and more interesting from the starting lines until the end.
    best rpa training in bangalore
    rpa training in bangalore | rpa course in bangalore
    RPA training in bangalore
    rpa training in chennai
    rpa online training

    ReplyDelete
  4. From your discussion I have understood that which will be better for me and which is easy to use. Really, I have liked your brilliant discussion. I will comThis is great helping material for every one visitor. You have done a great responsible person. i want to say thanks owner of this blog.
    python course institute in bangalore
    python Course in bangalore
    python training institute in bangalore

    ReplyDelete
  5. A very nice guide. I will definitely follow these tips. Thank you for sharing such detailed article. I am learning a lot from you.
    AWS Training in Bangalore

    AWS Training in pune

    ReplyDelete
  6. Your very own commitment to getting the message throughout came to be rather powerful and have consistently enabled employees just like me to arrive at their desired goals.
    AWS Online Training
    AWS Training in Bangalore

    ReplyDelete
  7. Thanks For sharing the Information The Information Shared Is Very valuable please Keep Updating Us The InFormation Shared Is Very Valuable Python Online Training Hadoop Online Training <a href="https://nareshit.com/data-science-online-training/>DataScience Online Training</a>

    ReplyDelete



  8. It is very good and useful for students and developer.Learned a lot of new things from your post Good creation,thanks for give a good information.
    aws training in chennai | aws training in annanagar | aws training in omr | aws training in porur | aws training in tambaram | aws training in velachery



    ReplyDelete
  9. Attend The Data Scientist Courses From ExcelR. Practical Data Scientist Courses Sessions With Assured Placement Support From Experienced Faculty. ExcelR Offers The Data Scientist Courses. Data Scientist Courses

    ReplyDelete
  10. Very nice blogs!!! i have to learning for lot of information for this sites…Sharing for wonderful information.Thanks for sharing this valuable information to our vision. You have posted a trust worthy blog keep sharing.

    Digital Marketing Training in Chennai

    Digital Marketing Course in Chennai

    ReplyDelete
  11. Your amazing insightful information entails much to me and especially to my peers. Thanks a ton; from all of us.
    data scientist training and placement

    ReplyDelete
  12. Great Article… I love to read your articles because your writing style is too good, its is very very helpful for all of us and I never get bored while reading your article because, they are becomes a more and more interesting from the starting lines until the end…

    DevOps Training in Hyderabad

    ReplyDelete
  13. Thanks for posting the best information and the blog is very gooddata science course in Lucknow

    ReplyDelete
  14. This is an excellent post I seen thanks to share it. It is really what I wanted to see hope in future you will continue for sharing such a excellent post. <a href="https://360digitmg.com/india/data-analytics-certification-training-course-in-surat>data analytics course in surat</a>

    ReplyDelete
  15. Impressive. Your story always bring hope and new energy. Keep up the good work.
    data scientist training in malaysia

    ReplyDelete
  16. Thanks for such a great post and the review, I am totally impressed! Keep stuff like this coming.
    full stack web development course

    ReplyDelete
  17. Cool stuff you have and you keep overhaul every one of us
    business analytics training in hyderabad

    ReplyDelete
  18. "Shri Mintu's Art forayed into the online furniture space as https://shrimintus.com/
    to offer value-for-money furniture made of sheesham wood to Indian consumers.
    The manufacturer and online seller provides finished
    as well as customised products to buyers.
    Enjoy a wide variety of traditional and modern living room furniture with shri Mintus Art."

    Wooden furniture

    ReplyDelete
  19. Thankyou for giving such informative blogs. Learn Java Course in Greater Noida for more understanding.

    ReplyDelete

  20. WhyDonate is één van de populairste crowdfunding platforms van alle Europese landen en de Verenigde Staten
    WhyDonate is niet alleen geschikt voor het opzetten van fondsenwervende campagnes, maar bevat ook vele actieve fondsenwervers waaraan men kan doneren.
    Top 10 crowdfunding platforms in België

    Crowdfunding Platfoarm

    ReplyDelete