Log4j 2.0 使用说明(2) 配置文件

这篇博客介绍了Log4j 2.0的配置文件使用,强调了2.0版本仅支持Xml和Json格式配置。通过示例展示了配置文件对日志输出的影响,如何设置默认配置,以及如何过滤特定包的trace级别日志。
摘要由CSDN通过智能技术生成

在这里我们试着添加配置文件。

另外,我们需要注意的是2.0版本中的配置只能为Xml和Json。

测试代码为:

package com.foo;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class Bar {

	static Logger logger = LogManager.getLogger(Bar.class.getName());

    public boolean doIt() {
      logger.entry();   //Log entry to a method
      logger.error("Did it again!");   //Log a message object with the ERROR level
      logger.exit();    //Log exit from a method 
      return false;
    }
}

import com.foo.Bar;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class MyApp {

	   // Define a static logger variable so that it references the
	   // Logger instance named "MyApp".
	   private static Logger logger = LogManager.getLogger(MyApp.class.getName());

	   public static void main(String[] args) {

评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值