Categories:
Audio (13)
Biotech (29)
Bytecode (36)
Database (77)
Framework (7)
Game (7)
General (507)
Graphics (53)
I/O (35)
IDE (2)
JAR Tools (102)
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 (322)
Collections:
Other Resources:
org.apache.commons.logging.Log System Property
How to use org.apache.commons.logging.Log system property to change the default logger?
✍: FYIcenter.com
If you want to change the default logger,
you can specify the system property
org.apache.commons.logging.Log=SomeLoggerClass
using the "-D" option when launching the JVM.
The following example runs the HelloCommonsLogging code with SimpleLog logger:
C:\fyicenter>java -cp .;C:\local\commons-logging-1.2\commons-logging-1.2.jar "-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog" HelloCommonsLogging Log class: org.apache.commons.logging.impl.SimpleLog [FATAL] MyLogging - Hello - fatal [ERROR] MyLogging - Hello - error [WARN] MyLogging - Hello - warn [INFO] MyLogging - Hello - info
The following example runs the HelloCommonsLogging code with Jdk14Logger logger:
C:\fyicenter>java -cp .;C:\local\commons-logging-1.2\commons-logging-1.2.jar "-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.Jdk14Logger" HelloCommonsLogging Log class: org.apache.commons.logging.impl.Jdk14Logger Nov 13, 2016 9:44:56 PM MyLogging main SEVERE: Hello - fatal Nov 13, 2016 9:44:56 PM MyLogging main SEVERE: Hello - error Nov 13, 2016 9:44:56 PM MyLogging main WARNING: Hello - warn Nov 13, 2016 9:44:56 PM MyLogging main INFO: Hello - info
The following example runs the HelloCommonsLogging code with Log4JLogger logger:
C:\fyicenter>java -cp .;C:\local\commons-logging-1.2\commons-logging-1.2.jar
"-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger"
HelloCommonsLogging
Exception in thread "main" java.lang.ExceptionInInitializerError
Caused by: org.apache.commons.logging.LogConfigurationException:
User-specified log class 'org.apache.commons.logging.impl.Log4JLogger'
cannot be found or is not useable.
at org.apache.commons.logging.impl.LogFactoryImpl
.discoverLogImplementation(LogFactoryImpl.java:804)
at org.apache.commons.logging.impl.LogFactoryImpl
.newInstance(LogFactoryImpl.java:541)
at org.apache.commons.logging.impl.LogFactoryImpl
.getInstance(LogFactoryImpl.java:292)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:669)
at HelloCommonsLogging.<clinit>(HelloCommonsLogging.java:5)
This exception is expected, because the Log4j JAR file is not specified.
⇒ What Is commons-logging.properties File?
⇐ Example of Default Apache Commons Logging
2017-05-29, ∼4637🔥, 0💬
Popular Posts:
How to read XML document with DTD validation from socket connections with the socket\DelayedInput.ja.. .
Smack is an Open Source XMPP (Jabber) client library for instant messaging and presence. A pure Java...
JDK 8 jconsole.jar is the JAR file for JDK 8 JConsole, which is a graphical monitoring tool to monit...
What Is activation.jar? I heard it's related to JAF (JavaBeans Activation Framework) 1.0.2? The if y...
JDK 17 jdk.internal.vm.ci.jmod is the JMOD file for JDK 17 Internal VM CI module. JDK 17 Internal VM...