首页 > 其他 > 详细

log4j的简介和使用

时间:2017-02-04 22:06:30      阅读:283      评论:0      收藏:0      [点我收藏+]

一、log4j是什么

     引用官网的介绍 

     Log4j is a fast and flexible framework for logging application debugging messages.

      With log4j it is possible to enable logging at runtime without modifying the application binary. The log4j package is designed so that these statements can remain in shipped code without incurring a heavy performance cost. Logging behavior can be controlled by editing a configuration file, without touching the application binary.

     log4j是一个快速且灵活的打印日志的框架。

二、log4j使用实例

     参考 http://www.codeceo.com/article/log4j-usage.html 

    注意:log4j的配置文件必须写在src/main/resource   或者  src/test/resource  中

三、log4j的基本使用

    1、 Log4j由三个重要的组件构成:级别、存放器和布局(日志以什么level什么layout输出到哪个appender)

     level:日记记录的优先级priority,优先级由高到低分为 OFF ,FATAL ,ERROR ,WARN ,INFO ,DEBUG ,ALL。 Log4j建议只使用FATAL ,ERROR ,WARN ,INFO ,DEBUG这五个级别。

    layout:输出格式则控制了日志信息的显 示内容。

    appender:输出源,目的地是console还是file。

    Log4j支持两种配置文件格式,一种是XML格式的文件,一种是Java特性文件(键=值)。

  2、log4j的第一种配置方式    log4j.properties

      参考链接:http://www.codeceo.com/article/log4j-usage.html

  3、log4j的XML格式文件      log4j.xml

      参考链接:http://zengxiantao.iteye.com/blog/1881706

    

log4j的简介和使用

原文:http://www.cnblogs.com/pyxrk/p/6366364.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!