• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: 小 中 大 | 推荐给好友 上一篇 | 下一篇

今天总算看完了log4j,心情不错!把自己的学习笔记拿出来给大家共享一把

发布: 2007-7-01 18:47 | 作者: admin | 来源: | 查看: 14次 | 进入软件测试论坛讨论

领测软件测试网 1.log4j有三种主要组件:logger、appender and layout2.Log4j提供的appender有以下几种:org.apache.log4j.ConsoleAppender(控制台)org.apache.log4j.FileAppender(文件)org.apache.log4j.DailyRollingFileAppender(每天产生一个日志文件)org.apache.log4j.RollingFileAppender(文件大小到达指定尺寸的时候产生一个新的文件)org.apache.log4j.WriterAppender(将日志信息以流格式发送到任意指定的地方)3.Log4j提供的layout有以下几种:org.apache.log4j.HTMLLayout(以HTML表格形式布局)org.apache.log4j.PatternLayout(可以灵活地指定布局模式)org.apache.log4j.SimpleLayout(包含日志信息的级别和信息字符串)org.apache.log4j.TTCCLayout(包含日志产生的时间、线程、类别等等信息)4.Log4j提供的几种输出格式:%M:Used to output the method name where the logging request was issued.%m:Used to output the application supplied message associated with the logging event.%l:Used to output location information of the caller which generated the logging event%L:Used to output the line number from where the logging request was issued.%p:Used to output the priority of the logging event.%n:Outputs the platform dependent line separator character or characters. %r:Used to output the number of milliseconds elapsed since the start of the application until the creation of the logging event.%F:Used to output the file name where the logging request was issued.%d:Used to output the date of the logging event. %c:Used to output the category of the logging event%C:Used to output the fully qualified class name of the caller issuing the logging request5.如果是对于效率要求比较高的话,要在log.debug()之前加上log.isDebugEnabled()进行判断,这样能够大大减少执行时间6.对于各个appenders,共有的属性是layout(一般设置为org.apache.log4j.PatternLayout),Threshold(Log的级别)(1)ConsoleAppender:Target(System.out和System.err)(2)FileAppender:File(定义输出的文件名),Append(定义是否为追加)(3)DailyRollingFileAppender(除FileAppender属性外):MaxFileSize(最大文件大小),MaxBackupIndex()


必要的时候可以参考一下:http://dev.csdn.net/develop/article/62/62201.shtm

延伸阅读

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备10010545号-5
技术支持和业务联系:[email protected] 电话:010-51297073

软件测试 | 领测国际 | ISTQB | ISTQB官网 | TMMi | TMMi认证 | 国际软件测试工程师认证 | 领测软件测试网