What do you write? Well, it's decadent recently. I haven't written a blog for a long time. I don't know what to write, but the level has dropped ......
Write something simple. log4j logging:
Jar package:
Commons-logging.jar
Log4j-1.2.15.jar
You can call it directly:
Import org. Apache. commons. Logging. log;
Import org. Apache. commons. Logging. logfactory;
Private log logger = logfactory. getlog (this. getclass ());
Public String returnuserinfo (){
Logger. debug ("userinfo object returned ");
Userinfo = new userinfo ();
Userinfo. setuserid (10000 );
Userinfo. setusername ("James ");
Userinfo. setpassword ("000000 ");
Return "userinfo ";
}
You need to understand that the log level is:
Debug <info <warn <error <fatal
Finally, the printing level of log4j. properties configuration is OK. For details, refer to the configuration file of Sun online pet store:
# For JBoss: Avoid to setup log4j outside $ jboss_home/Server/default/deploy/log4j. xml!
# For all other servers: comment out the log4j listener in Web. XML to activate log4j
Log4j. rootlogger = info, stdout, logfile -- info indicates the log level, stdout indicates the standard output, and logfile indicates the output to the file.
Log4j. appender. stdout = org. Apache. log4j. leleappender -- standard output to the console
Log4j. appender. stdout. layout = org. Apache. log4j. patternlayout
Log4j. appender. stdout. layout. conversionpattern = % d % P [% C]-% m % N
Log4j. appender. logfile = org. Apache. log4j. rollingfileappender
Log4j. appender. logfile. File =$ {PetStore. Root}/WEB-INF/PetStore. log -- location of the log file
Log4j. appender. logfile. maxfilesize = 512kb
# Keep three backup files.
Log4j. appender. logfile. maxbackupindex = 3
# Pattern to output: date priority [category]-message
Log4j. appender. logfile. layout = org. Apache. log4j. patternlayout
Log4j. appender. logfile. layout. conversionpattern = % d % P [% C]-% m % N