从log4j迁移到log4j2 [英] log4j migration to log4j2

查看:205
本文介绍了从log4j迁移到log4j2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Log4j迁移指南

https://logging.apache.org/log4j/2. x/manual/migration.html

声明

调用接受LoggerFactory的org.apache.log4j.Logger.getLogger必须删除org.apache.log4j.spi.LoggerFactory并使用Log4j 2的其他扩展机制之一.

Calls to org.apache.log4j.Logger.getLogger that accept a LoggerFactory must remove the org.apache.log4j.spi.LoggerFactory and use one of Log4j 2's other extension mechanisms.

log4j2中可用的扩展机制是什么,以及如何最好地迁移log4j2中的以下方法

What are the extension mechanisms available in log4j2 and how best to migrate a method like below in log4j2

private static TraceLoggerFactory stTraceFactory = new TraceLoggerFactory();

public static Logger getTraceLogger(final String name) {
    return getLogger(name, stTraceFactory);
}


class TraceLoggerFactory implements LoggerFactory {
    @Override
    public Logger makeNewLoggerInstance(final String name) {
        return new TraceLogger(name);
    }
}

推荐答案

您发布的代码未显示接受LoggerFactorygetLogger方法的使用,因此我假设您正在调用getLogger方法并将其传递给您的TraceLoggerFactory.

The code you posted doesn't show the use of the getLogger method that accepts a LoggerFactory so I'll just assume you are calling the getLogger method and passing it your TraceLoggerFactory.

扩展Log4j页面上列出了其他扩展机制" .

就如何最好地迁移代码而言,如果不了解当前自定义的目的,就不可能提出建议.例如-TraceLogger的目的是什么?

As far as how best to migrate your code, it's not really possible to give recommendations without understanding the purpose of your current customization. For example - what is the purpose of TraceLogger?

我建议您花一些时间详细研究log4j并确定您是否确实需要自定义,或者是否可以使用log4j的提供的功能.自定义会增加您的长期维护成本,只有在绝对必要时才应该进行自定义.

I suggest you take the time to research log4j in more detail and determine if you really need your customization or if you can use the provided features of log4j instead. Customization increases your long term maintenance and should only be done when absolutely necessary.

这篇关于从log4j迁移到log4j2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆