Java Logging API usage

Source: Internet
Author: User
When you are developing a program, debugging (debugging) and logging are very important tasks. However, there are too many logging APIs available because they are both good, it is difficult to make a choice. the foreign java Forum also has some discussions on these logging methods.
While common logging is a small bridge between these different logging APIs. currently, the most famous Log method in Java is Log4j and JDK 1.4 Logging API. in addition, there are LogKit and so on used in aveon. commons-logging also implements some basic logging methods: NoOpLog and SimpleLog. their comparison is not in the scope of this discussion,
If you are interested, please refer to the reference file.
The quick use of Logging is actually very simple to use, put the commons-logging.jar under/WEB-INF/lib. Then write the following code
LoggingTest. java
Package com. softleader. newspaper. java. opensource;
Import org. apache. commons. logging. Log;
Import org. apache. commons. logging. LogFactory;
Public class LoggingTest {
Log log = LogFactory. getLog (LoggingTest. class );
Public void hello (){
Log. error ("ERROR ");
Log. debug ("DEBUG ");
Log. warn ("WARN ");
Log.info ("INFO ");
Log. trace ("TRACE ");
System. out. println ("OKOK ");
}
}
Place a jsp test test-commons-logging.jsp/
<% @ Page import = "com. softleader. newspaper. java. opensource. LoggingTest" %>
<% LoggingTest test = new LoggingTest (); test. hello (); %>
You will see the following output in the tomcat console
Log4j: WARN No appenders cocould be found for logger (com. softleader. newspaper. java. opensource. LoggingTest ).
Log4j: WARN Please initialize the log4j system properly. OKOK

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.