BasicConfigurator replacement in log4j2

2019-05-23 12:28发布

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.

2条回答
我欲成王,谁敢阻挡
2楼-- · 2019-05-23 13:06

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);
查看更多
Bombasti
3楼-- · 2019-05-23 13:21
Configurator.initialize(new DefaultConfiguration());
查看更多
登录 后发表回答