slf4j (simple logging facade for java)

13
Albert Guo [email protected]

Upload: guo-albert

Post on 19-May-2015

3.001 views

Category:

Technology


4 download

TRANSCRIPT

Page 1: SLF4J (Simple Logging Facade for Java)

Albert [email protected]

Page 2: SLF4J (Simple Logging Facade for Java)

What is SLF4J? When should SLF4J be used? What are SLF4J's requirements? Parameterized logging Migration Who use SLF4J Demo

2

Page 3: SLF4J (Simple Logging Facade for Java)

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.

http://www.slf4j.org/

3

Page 4: SLF4J (Simple Logging Facade for Java)

4

Page 5: SLF4J (Simple Logging Facade for Java)

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.

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.

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.

5

Page 6: SLF4J (Simple Logging Facade for Java)

6

Page 7: SLF4J (Simple Logging Facade for Java)

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

7

Page 8: SLF4J (Simple Logging Facade for Java)

inefficient style◦ logger.debug("Hello "+name);

new style◦ logger.debug("Hello {}", name);

8

Page 9: SLF4J (Simple Logging Facade for Java)

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.

For further information, please check: http://www.slf4j.org/migrator.html

9

Page 10: SLF4J (Simple Logging Facade for Java)

• Apache Archiva • Apache Directory • Apache FTPServer • Apache Geronimo • Apache Graffito • Apache Jetspeed• Apache Jackrabbit • Apache Mina • Apache Qpid • Apache Sling • Apache Tapestry • Apache Wicket• Aperture• Apogee

• Artifactory • Bitronix • DbUnit • Display tag • GMaven • Gradle• GreenMail • GumTree • H2 Database • HA-JDBC • Hibernate • Igenko • Jabsorb

• Jetty v6 • jLynx • JMesa • JODConverter• JTrac • JWebUnit 2.x • LIFERAY • log4jdbc • Magnolia • MRCP4J • Mindquarry • Mugshot • Mule

•Novocode •NetCDF •OpenRDF •Penrose •Proximity •PZFileReader •QuickFIX/J •SMSJ •Spring-OSGi •StreamBase •TimeFinder •WTFIGO •YASL •Xooctory

10

Page 11: SLF4J (Simple Logging Facade for Java)

11

Page 12: SLF4J (Simple Logging Facade for Java)

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…

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…12

Page 13: SLF4J (Simple Logging Facade for Java)

You don’t need to do any changes.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...

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... 13