标签:
首先需求slf4j-api-1.5.8.jar和slf4j-log4j12-1.5.8.jar包
然后在src下创建log4j.properties文件,添加
# # XXX GeeData Logging Configuration # log4j.rootLogger=info, stdout, R #stdout log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.Target=System.out log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%5p %d{yy-MM-dd HH:mm:ss} %c:%L - %m%n #file log4j.appender.R=org.apache.log4j.RollingFileAppender log4j.appender.R.File=logs/mylog.log #指定日志输出的路径 log4j.appender.R.Threshold=INFO log4j.appender.R.MaxFileSize=100MB log4j.appender.R.MaxBackupIndex=10 log4j.appender.R.layout=org.apache.log4j.PatternLayout # [\u673A\u5668ip|\u65E5\u5FD7\u7EA7\u522B|\u65F6\u95F4] [\u7EBF\u7A0B\u540D|\u7C7B\u540D|\u65B9\u6CD5\u540D|\u884C\u53F7] [\u4EA7\u54C1id|\u7248\u672C\u53F7] message log4j.appender.R.layout.ConversionPattern=[%X{ip}|%p|%d{yyyy-MM-dd HH\:mm\:ss}] [%t|%C|%M|%L] [%X{productname}|%X{productversion}] - %m%n
在代码里面直接引用slf4j包,就可以用了
import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class CrTemplateAction extends BaseAction implements ModelDriven<CrTemplate>{ private static final Logger log = LoggerFactory.getLogger(CrTemplateAction.class); log.info("解码‘网站名称’出错。"); }
标签:
原文地址:http://www.cnblogs.com/junrong624/p/4914076.html