野性向日葵

导航

log4j的简介和使用

一、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

    

posted on 2017-02-04 21:18  野性向日葵  阅读(179)  评论(0编辑  收藏  举报