Categories:
Audio (13)
Biotech (29)
Bytecode (36)
Database (77)
Framework (7)
Game (7)
General (507)
Graphics (53)
I/O (35)
IDE (2)
JAR Tools (101)
JavaBeans (21)
JDBC (121)
JDK (426)
JSP (20)
Logging (108)
Mail (58)
Messaging (8)
Network (84)
PDF (97)
Report (7)
Scripting (84)
Security (32)
Server (121)
Servlet (26)
SOAP (24)
Testing (54)
Web (15)
XML (309)
Collections:
Other Resources:
SLF4J Binding to JDK Loger Example
How to use SLF4J API with JDK Logger?
✍: Guest
If you want to use SLF4J API with JDK Logger,
you need specify slf4j-api-*.jar and slf4j-jdk14-*.jar
in Java classpath as shown in this tutorial.
1. Write a simple Java program, Hello.java, to use SLF4J API:
// Copyright (c) FYIcenter.com import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class Hello { private static final Logger log = LoggerFactory.getLogger("fyiLog"); public static void main(String[] args) { System.out.println("Log class: "+log.getClass().getName()); log.error("Hello - error"); log.warn("Hello - warn"); log.info("Hello - info"); log.debug("Hello - debug"); log.trace("Hello - trace"); } }
2. Run Hello.java with slf4j-api-1.7.31.jar and slf4j-jdk14-1.7.31.jar.
$ java -version java version "15" 2020-09-15 $ java -cp slf4j-api-1.7.31.jar:slf4j-jdk14-1.7.31.jar Hello.java Log class: org.slf4j.impl.JDK14LoggerAdapter Jul 04, 2021 6:04:27 PM Hello main SEVERE: Hello - error Jul 04, 2021 6:04:27 PM Hello main WARNING: Hello - warn Jul 04, 2021 6:04:27 PM Hello main INFO: Hello - info
3. Review the output:
⇒ SLF4J Binding to Log4J Loger Example
⇐ SLF4J Binding to Simple Logger Example
2021-12-23, 616🔥, 0💬
Popular Posts:
JRE 8 deploy.jar is the JAR file for JRE 8 Java Control Panel and other deploy tools. JRE (Java Runt...
JDK 1.1 source code directory contains Java source code for JDK 1.1 core classes: "C:\fyicenter\jdk-...
JDK 17 jdk.hotspot.agent.jmod is the JMOD file for JDK 17 Hotspot Agent module. JDK 17 Hotspot Agent...
How to read XML document from socket connections with the socket\DelayedInput.java provided in the A...
What JAR files are required to run dom\Counter.java provided in the Apache Xerces package? You can f...