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 No Binding Example
What happens if I use slf4j-api-*.jar without any logging library to bind with?
✍: Guest
If you use slf4j-api-*.jar only, you will get a warning message.
And all logging messages will be dropped 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 only.
$ java -version java version "15" 2020-09-15 $ java -cp slf4j-api-1.7.31.jar Hello.java SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". SLF4J: Defaulting to no-operation (NOP) logger implementation SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details. Log class: org.slf4j.helpers.NOPLogger
3. Review the output:
⇒ SLF4J Binding to Simple Logger Example
⇐ Using slf4j-*.jar in Java Programs
2021-12-23, 887🔥, 0💬
Popular Posts:
What is the dom\GetElementsByTagName .javaprovided in the Apache Xerces package? I have Apache Xerce...
What Is commons-net-ftp-2.0.jar? commons-net-ftp-2.0.jar is the JAR file for Apache Commons Net FTP ...
JDK 17 jdk.hotspot.agent.jmod is the JMOD file for JDK 17 Hotspot Agent module. JDK 17 Hotspot Agent...
Apache Neethi provides general framework for the programmers to use WS Policy. It is compliant with ...
What Is javaws.jar in JRE (Java Runtime Environment) 8? javaws.jar in JRE (Java Runtime Environment)...