Log4jar Package +log4j.properties Baidu Cloud Permanent Effective: https://pan.baidu.com/s/15WZ-lcBPgFa-a6lkTVVvYw
1 Import the jar package (directly copy the jar package into the Lib directory, then build path), and then create a new log4j.properties file: Baidu Cloud has log4j writing standard tutorial.
Log4j.rootlogger=INFO, stdout, Rlog4j.appender.stdout=Org.apache.log4j.ConsoleAppenderlog4j.appender.stdout.layout=org.apache.log4j.patternlayout# Pattern to output the caller' s file name and line number. #log4j. appender.stdout.layout.conversionpattern=%5p [%t] (%f:%l)-%m%n# Print The date in ISO8601Formatlog4j.appender.stdout.layout.ConversionPattern=%d [%t]%-5p%c-%m%NLOG4J.APPENDER.R=Org.apache.log4j.rollingfileappenderlog4j.appender.r.file=example.loglog4j.appender.r.maxfilesize=100kb# Keep One backup Filelog4j.appender.r.maxbackupindex=1Log4j.appender.r.layout=Org.apache.log4j.patternlayoutlog4j.appender.r.layout.conversionpattern=%p%t%c-%m%n# Print Only messages of level WARN or above in the PackageCOM.FOO.LOG4J.LOGGER.COM.IMOOC=info
2 Creating a tool class
Public class Log { publicstatic Logger Logger = logger.getlogger (log. Class. GetName ()); }
3 Direct call.
Like what:
catch (Exception e) {Log.logger.error (E.getmessage ()); E.printstacktrace ();}
Log.logger.info ("The parameter you passed in");
If you want to make SQL statements or some database information in the console: To configure in Mybatis.xml:
<settings><setting name= "Logimpl" value= "stdout_logging"/> <settings>
MyBatis output The log with log4j, and output SQL to the console