当前位置:首页 > 开发 > 开源软件 > 正文

【Log4j一】Log4j总体介绍

发表于: 2014-09-17   作者:bit1129   来源:转载   浏览:
摘要: Log4j组件:Logger、Appender、Layout   Log4j核心包含三个组件:logger、appender和layout。这三个组件协作提供日志功能: 日志的输出目标 日志的输出格式 日志的输出级别(是否抑制日志的输出)  logger继承特性 A logger is said to be an ancestor of anothe

Log4j组件:Logger、Appender、Layout

 

Log4j核心包含三个组件:logger、appender和layout。这三个组件协作提供日志功能:

  • 日志的输出目标
  • 日志的输出格式
  • 日志的输出级别(是否抑制日志的输出)

 logger继承特性

A logger is said to be an ancestor of another logger if its name followed by a dot is a prefix of the descendant logger name. A logger is said to be a parent of a child logger if there are no ancestors between itself and the descendant logger。For example, the logger named "com.foo" is a parent of the logger named "com.foo.Bar". Similarly, "java" is a parent of "java.util" and an ancestor of "java.util.Vector". This naming scheme should be familiar to most developers

 

Logger日志级别

  • TRACE
  • DEBUG
  • INFO
  • WARN
  • ERROR
  • FATAL

 

1. 上面的六个日志级别,从上到下级别逐次提高。A logging request(即调用logger的日志输出方法debug,info,war,error等) is said to be enabled if its level is higher than or equal to the level of its logger. Otherwise, the request is said to be disabled. A logger without an assigned level will inherit one from the hierarchy.

2. 假如c是logger对象,并且c的日志级别设置为INFO,那么只有c.info..c.fatal的日志调用才会真正的将日志打印到相应的目标上,c.debug则会抑制日志的输出

2. 一个logger最多指定一个级别

 

日志级别继承特性

The inherited level for a given logger C, is equal to the first non-null level in the logger hierarchy, starting at C and proceeding upwards in the hierarchy towards the root logger.

如果root logger的日志级别进行了设置,那么所有的logger,都会有不为空的日志级别。实际项目开发中,应该为root logger指定一个默认的日志级别。那面的两个表格是两个日志级别继承的例子:




Loggername Assignedlevel Inheritedlevel
root Proot Proot
X Px Px
X.Y none Px
X.Y.Z Pxyz Pxyz

 




Loggername Assignedlevel Inheritedlevel
root Proot Proot
X Px Px
X.Y none Px
X.Y.Z Pxyz Pxyz

 

 

Appender、Layout

在Log4j中,日志输出目标称之为Appender。一个logger可以打印到多个目标,也就是说一个logger可以配置多个appender。Log4j内置了如下几种Appender:

  • DailyRollingFileAppender    按日期滚动文件
  • RollingFileAppender 按文件大小滚动文件
  • ConsoleAppender   打印到控制台
  • JDBCAppender       将日志打印到数据库中
  • JMSAppender         将日志打印到JMS中
  • SocketAppender     将日志打印到log服务器(LogEvent对象序列化到日志服务器)
  • ...

每个appender因为目标介质的不同以及方式的不同,每个类都有特定的一些属性(用于配置)

 

 

Appender Additivity(logger绑定多个appender的策略)

1. Each enabled logging request for a given logger will be forwarded to all the appenders in that logger as well as the appenders higher(higher here means the hierarchy relationship of logger) in the hierarchy. In other words, appenders are inherited additively from the logger hierarchy. For example, if a console appender is added to the root logger, then all enabled logging requests will at least print on the console. If a file appender is also added to a logger, say C, then enabled logging requests for C and C's children will print on a file and on the console. It is possible to override this default behavior so that appender accumulation is no longer additive by setting the additivity to false.

2. Loggers have their additivity flag set to true by default.

 

Appender Additivity中断(logger绑定多个appender的策略)

 

The output of a log statement of logger C will go to all the appenders in C and  to all appenders that are defined in its ancestors. This is the meaning of the term "appender additivity".However, if an ancestor of logger C, say P, has the additivity flag set to false, then C's output will be directed to all the appenders in C and its ancestors upto and including P but not the appenders in any of the ancestors of P.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

【Log4j一】Log4j总体介绍

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

编辑推荐
1、Log4j体系(配置文件)中主要由一下三部分组成。 2、log4j的优先级别: 在Log4j体系中共有八个级别
log4j是一个非常强大的log记录软件,下面我们就来看看在项目中如何使log4j。 首先当然是得到log4j的
工作闲着,快速回顾一下spring框架。Spring框架,是进行对象管理,对象关联,解耦的一个中间层框架
前边讲述了用于处理数据流程的Struts2的框架,和用于操作数据的IBatis持久层框架,这篇博客开始总结
这篇博客开始将总结一下有关框架的知识,在开发中合适的利用框架会使我们的开发效率大大提高。当今
6 log4j
log4j是一个非常强大的log记录软件,下面我们就来看看在项目中如何使log4j。 首先当然是得到log4j的
7 log4j
http://www.iteye.com/topic/378077 log4j是一个非常强大的log记录软件,下面我们就来看看在项目中
8 log4j
log4j是一个非常强大的log记录软件,下面我们就来看看在项目中如何使log4j。 首先当然是得到log4j的
9 Log4J
1、Log4J主要由以下3大组件构成: (1)Logger:负责生成日志,并能够对日志信息进行分类筛选 一个L
10 Log4j
Log4j的类图 Logger - 日志写出器,供程序员输出日志信息 Appender - 日志目的地,把格式化好的日志
版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号