在log4j2中替换BasicConfigurator[英] BasicConfigurator replacement in log4j2

本文是小编为大家收集整理的关于在log4j2中替换BasicConfigurator的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我正在使用log4j 1到log4j 2迁移.在AppConfiginitializer文件中,我们使用类似的内容 -

BasicConfigurator.configure(consoleAppender);

我该替换为log4j2中的功能.我也在使用向后兼容桥,但这破坏了基本配置器的实现.

我认为我需要使用Config File进行此操作,但无法找到方法.

推荐答案

上面的解决方案可行,但是由于默认日志级别是错误,因此并非所有日志显示.可以使用configurator.setRootlevel方法来调整日志级别:

    Configurator.initialize(new DefaultConfiguration());
    Configurator.setRootLevel(Level.INFO);

其他推荐答案

Configurator.initialize(new DefaultConfiguration());

本文地址:https://www.itbaoku.cn/post/1575208.html

问题描述

I am working on a log4j 1 to log4j 2 migration. Inside a AppConfigInitializer file we use something like this -

BasicConfigurator.configure(consoleAppender);

What shall I replace this with to get it working in log4j2. I am using the backward compatibility bridge as well but that has broken BasicConfigurator implementation.

I think I need to do this using config file, but not able to find how.

推荐答案

The solution above works, but since default log level is ERROR, not all logs are shown. Log level can be adjusted with Configurator.setRootLevel method:

    Configurator.initialize(new DefaultConfiguration());
    Configurator.setRootLevel(Level.INFO);

其他推荐答案

Configurator.initialize(new DefaultConfiguration());