SLF4J (Simple Logging Facade for Java)

3,924 views

Published on

Published in: Technology, Education

SLF4J (Simple Logging Facade for Java)

  1. 1. Albert Guo [email_address]
  2. 2. <ul><li>What is SLF4J? </li></ul><ul><li>When should SLF4J be used? </li></ul><ul><li>What are SLF4J's requirements? </li></ul><ul><li>Parameterized logging </li></ul><ul><li>Migration </li></ul><ul><li>Who use SLF4J </li></ul><ul><li>Demo </li></ul>
  3. 3. <ul><li>The Simple Logging Facade for Java or (SLF4J) serves as a simple facade or abstraction for various logging frameworks, e.g. java.util.logging, log4j and logback, allowing the end user to plug in the desired logging framework at deployment time. </li></ul><ul><li>http://www.slf4j.org/ </li></ul>
  4. 4.
  5. 5. <ul><li>Suppose that your CRM application uses log4j for its logging. However, one of your important clients request that logging be performed through JDK 1.4 logging. </li></ul><ul><li>If your application is riddled with thousands of direct log4j calls, migration to JDK 1.4 would be a relatively lengthy and error-prone process. Even worse, you would potentially need to maintain two versions of your CRM software. </li></ul><ul><li>Had you been invoking SLF4J API instead of log4j, the migration could be completed in a matter of minutes by replacing one jar file with another . </li></ul>
  6. 6.
  7. 7. Binding Requirements slf4j-nop JDK 1.3 slf4j-simple JDK 1.3 slf4j-log4j12 JDK 1.3, plus any other library dependencies required by the log4j appenders in use slf4j-jdk14 JDK 1.4 or above logback-classic JDK 1.5 or above, plus any other library dependencies required by the logback appenders in use
  8. 8. <ul><li>inefficient style </li></ul><ul><ul><li>logger.debug(&quot;Hello &quot;+name); </li></ul></ul><ul><li>new style </li></ul><ul><ul><li>logger.debug(&quot;Hello {}&quot;, name); </li></ul></ul>
  9. 9. <ul><li>The SLF4J migrator is a small Java tool for migrating Java source files from the Jakarta Commons Logging (JCL) API to SLF4J. It can also migrate from the log4j API to SLF4J, or from java.util.logging API to SLF4J. </li></ul><ul><li>For further information, please check: http://www.slf4j.org/migrator.html </li></ul>
  10. 10. <ul><li>Apache Archiva </li></ul><ul><li>Apache Directory </li></ul><ul><li>Apache FTPServer </li></ul><ul><li>Apache Geronimo </li></ul><ul><li>Apache Graffito </li></ul><ul><li>Apache Jetspeed </li></ul><ul><li>Apache Jackrabbit </li></ul><ul><li>Apache Mina </li></ul><ul><li>Apache Qpid </li></ul><ul><li>Apache Sling </li></ul><ul><li>Apache Tapestry </li></ul><ul><li>Apache Wicket </li></ul><ul><li>Aperture </li></ul><ul><li>Apogee </li></ul><ul><li>Artifactory </li></ul><ul><li>Bitronix </li></ul><ul><li>DbUnit </li></ul><ul><li>Display tag </li></ul><ul><li>GMaven </li></ul><ul><li>Gradle </li></ul><ul><li>GreenMail </li></ul><ul><li>GumTree </li></ul><ul><li>H2 Database </li></ul><ul><li>HA-JDBC </li></ul><ul><li>Hibernate </li></ul><ul><li>Igenko </li></ul><ul><li>Jabsorb </li></ul><ul><li>Jetty v6 </li></ul><ul><li>jLynx </li></ul><ul><li>JMesa </li></ul><ul><li>JODConverter </li></ul><ul><li>JTrac </li></ul><ul><li>JWebUnit 2.x </li></ul><ul><li>LIFERAY </li></ul><ul><li>log4jdbc </li></ul><ul><li>Magnolia </li></ul><ul><li>MRCP4J </li></ul><ul><li>Mindquarry </li></ul><ul><li>Mugshot </li></ul><ul><li>Mule </li></ul><ul><li>Novocode </li></ul><ul><li>NetCDF </li></ul><ul><li>OpenRDF </li></ul><ul><li>Penrose </li></ul><ul><li>Proximity </li></ul><ul><li>PZFileReader </li></ul><ul><li>QuickFIX/J </li></ul><ul><li>SMSJ </li></ul><ul><li>Spring-OSGi </li></ul><ul><li>StreamBase </li></ul><ul><li>TimeFinder </li></ul><ul><li>WTFIGO </li></ul><ul><li>YASL </li></ul><ul><li>Xooctory </li></ul>
  11. 11.
  12. 12. 2009-11-24 16:21:42,203 INFO slf4j.MyProgram.printLog( MyProgram.java:11) - print info level log... 2009-11-24 16:21:42,234 DEBUG slf4j.MyProgram.printLog( MyProgram.java:12) - print debug level log... 2009-11-24 16:21:42,234 ERROR slf4j.MyProgram.printLog( MyProgram.java:13) - print error level log…
  13. 13. You don’t need to do any changes. 2009/11/24 下午 04:29:45 org.slf4j.impl.JCLLoggerAdapter info 資訊 : print info level log... 2009/11/24 下午 04:29:45 org.slf4j.impl.JCLLoggerAdapter error 嚴重的 : print error level log...

×