jsp-log4j 日志 简单用法笔记
1、从官方网站下载 jakarta-log4j-1.2.1.tar.gz http://logging.apache.org/log4j/1.2/download.html
2、在eclipse中将log4j-1.2.1.jar复制到WebContent/WEB-INF/lib 下
3、在src下新建File,命名为 log4j.properties(不要改动)
4、在log4j.properties中写入配置文件(从帮助文档中复制一段,具体配置查看其他信息)
如:
log4j.rootLogger=debug, stdout, R log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.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 log4j.appender.R=org.apache.log4j.RollingFileAppender log4j.appender.R.File=D:/example.log log4j.appender.R.MaxFileSize=100KB # Keep one backup file log4j.appender.R.MaxBackupIndex=1 log4j.appender.R.layout=org.apache.log4j.PatternLayout log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n
注:第7行可配置所生成日志文件位置
5、现在便可以使用了,如在某一个Servlet中使用:
private static Logger loger=Logger.getLogger(AddServlet.class); //AddServlet.class为当前Servlet名 loger.debug("用户使用了添加功能");
相关推荐
chw0 2020-11-04
sdaq 2020-07-26
MrLiar 2020-07-07
sdaq 2020-06-16
丨Fanny丨Cri 2020-06-13
CXC0 2020-06-08
MrLiar 2020-06-04
丨Fanny丨Cri 2020-06-03
丨Fanny丨Cri 2020-05-17
JavaWinner 2020-05-10
JavaWinner 2020-05-04
CXC0 2020-04-20
CXC0 2020-04-10
丨Fanny丨Cri 2020-02-18
MrLiar 2020-02-16
CXC0 2020-02-09