标签:test rtt imp bug als blog 方式 text public
1. 在maven中配置log4j的依赖
|
在src新建一个log4j.properties内容如下
log4j.rootLogger=DEBUG,console,FILE log4j.rootLogger=info,stdout,tracelog log4j.appender.Root.Encoding=UTF-8 log4j.additivity.org.apache=false log4j.appender.tracelog=org.apache.log4j.FileAppender log4j.appender.tracelog.Encoding=UTF-8 log4j.appender.tracelog.File=./log/project.log log4j.appender.D.Threshold = DEBUG ## è????oDEBUG?o§?????¥????????¥??? log4j.appender.tracelog.layout=org.apache.log4j.PatternLayout log4j.appender.tracelog.layout.ConversionPattern=%d{yyyy-MM-dd-HH:mm:ss}(%F:%L)%m%n
log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%-5p%d{yyyy-MM-dd-HH:mm:ss}(%F:%L)%m%n |
实例log
package until; import org.apache.log4j.Logger; import org.apache.log4j.PropertyConfigurator; public class logTest { public static Logger logger = Logger.getLogger(logTest.class); public logTest() { PropertyConfigurator.configure("log4j.properties"); } public static void logInfo(Object message) { logger.info(message); } public static void logError(Object message) { logger.error(message); // Assert.assertTrue(false);可以扩展讲下,断言的几种方式 } public static void logWarn(Object message) { logger.warn(message); } } |
package until; public class test { public static void main(String[] args) { logTest.logInfo("12"); } } |
效果如图
项目截图
标签:test rtt imp bug als blog 方式 text public
原文地址:http://www.cnblogs.com/chongyou/p/7516393.html