1, about logging is the development of essential knowledge, now give you a detailed talk about how to record log information; the principle is not much said to see the actual operation
2, configure the log4j file: The specific configuration of what means to do not say a look at the understand Hey
Log4j.rootcategory=debug,stdlog,errorlog
Log4j.appender.stdout=org.apache.log4j.consoleappender
Log4j.appender.stdout.threshold=error
Log4j.appender.stdlog.file=d:/error.log
Log4j.appender.stdout.layout=org.apache.log4j.patternlayout
Log4j.appender.stdout.layout.conversionpattern=%d{yyyy/mm/dd HH:mm:ss} [%c{1}]-%m%n
Log4j.appender.stdlog=org.apache.log4j.rollingfileappender
Log4j.appender.stdlog.threshold=debug,console
Log4j.appender.stdlog.file=d:/debug.log
log4j.appender.stdlog.maxfilesize=1024kb
Log4j.appender.stdlog.maxbackupindex=3
Log4j.appender.stdlog.layout=org.apache.log4j.patternlayout
LOG4J.APPENDER.STDLOG.LAYOUT.CONVERSIONPATTERN=%D{YYYY/MM/DD HH:mm:ss}%-5p [%c{1}]-%m%n
Log4j.appender.errorlog=org.apache.log4j.rollingfileappender
Log4j.appender.errorlog.threshold=warn
Log4j.appender.errorlog.file=d:/warn.log
log4j.appender.errorlog.maxfilesize=1024kb
Log4j.appender.errorlog.maxbackupindex=3
Log4j.appender.errorlog.layout=org.apache.log4j.patternlayout
log4j.appender.errorlog.layout.conversionpattern=%d [%c{1}]-%m%n
3, Specific code:
Log4jlogger L = new Log4jlogger ("Log4j.properties"); Initialize Log driver
L.logdebug ("--->dug record");
L.logerror ("Log is recording ...");
L.loginfo ("message record ...");
try {
Log4jlogger LL = null;
Ll.logdebug ("---");
catch (Exception e) {
L.logdebug (E, E.fillinstacktrace ());
L.logerror (E,e.fillinstacktrace ());
}
4, saved log information:
2013/01/24 16:51:03 ERROR [Properties]-Log is recording ...
2013/01/24 16:51:03 INFO [Properties]-Message Records ...
2013/01/24 16:51:03 DEBUG [Properties]-java.lang.NullPointerException
Java.lang.NullPointerException
At DDM. Datadrivermanager.showsysinfo (datadrivermanager.java:47)
At DDM. Datadrivermanager.main (DATADRIVERMANAGER.JAVA:20)
2013/01/24 16:51:03 ERROR [Properties]-java.lang.NullPointerException
Java.lang.NullPointerException
At DDM. Datadrivermanager.showsysinfo (datadrivermanager.java:48)
At DDM. Datadrivermanager.main (DATADRIVERMANAGER.JAVA:20)
5, the Gaocheng. Think you can of the brothers hope to give a good opinion.
6,QQ Group: 180258862