Adding logs in Java

Source: Internet
Author: User

To add a log to a simple project:

Import 2 jar Packages first

Commons-logging-1.1.1.jar

Log4j-1.2.15.jar

Then create the log configuration file in the SRC directory of the project Log4j.properties content as follows:

# # Defines the DEBUG priority, R for the purpose of the log output
#log4j. rootlogger= Debug,r
# # Set the log output type to file type
#log4j. appender.r= Org.apache.log4j.FileAppender
# # Set the log file name LogRecord.log, output to the Tomcat server's logs directory
#log4j. appender.r.target=system.out
#//log4j.appender.r.file=. /log/logrecord.log
# # each time a new log message is written at the end of the file
#log4j. appender.r.append= true
# # Log Output Information format type
#log4j. appender.r.layout= org.apache.log4j.PatternLayout
# # The log Output Information format is newline, date, priority, [Full-class name], log information, line wrapping

Refer to: http://blog.csdn.net/wud_jiyanhui/article/details/6213443

Http://www.blogjava.net/zzzlyr/articles/353039.html, etc.

Then create a class that applies the log in the class

Propertyconfigurator.configure (Classloader.getsystemresource ("log4j.properties")); Can save you from not writing

Log log = Logfactory.getlog (Nettytest.class); The parameter is the location where the log is to be monitored.

Log.info ("Http Server listening on 9990 ..."); Add an info log record.

Adding logs in Java

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.