slf4j (simple logging facade for java)

Post on 19-May-2015

3.009 Views

Category:

Technology

4 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Albert Guojunyuo@gmail.com

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

2

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

4

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

6

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

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

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

8

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

• 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

11

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

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

top related