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