log4jar包+log4j.properties百度云下载地址永久有效: https://pan.baidu.com/s/15WZ-lcBPgFa-a6lkTVVvYw
1 导入jar包(直接复制jar包到lib目录下,然后build path),然后新建log4j.properties文件: 百度云中有log4j的书写规范教程。
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 ISO 8601 formatlog4j.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 package com.foo.log4j.logger.com.imooc=INFO
2 创建工具类
public class Log { public static Logger logger = Logger.getLogger(Log.class.getName()); }
3 直接调用即可。
比如:
catch(Exception e){ Log.logger.error(e.getMessage()); e.printStackTrace(); }
Log.logger.info(“你传入的参数”);
如果想在控制台打出sql语句或者一些数据库信息:要在mybatis.xml中配置: