我正在尝试将 log4j 升级到 log4j2。我尝试升级的特定代码行是:
log(targetClass, Priority.DEBUG_INT, message, null);
静态场Priority.DEBUG_INT
在新版本中不再可用Priority
。相反,它看起来像getPriority(Facility facility, org.apache.logging.log4j.Level level)
静态方法用于访问priority int值,其中DEBUG
可以指定为Level
.
然而,这种方法也需要一个Facility
待指定。我怎么知道哪个Facility
调用时指定getPriority
?
旧优先级:https://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/Priority.html https://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/Priority.html
新优先级:https://logging.apache.org/log4j/2.x/log4j-core/apidocs/org/apache/logging/log4j/core/net/Priority.html https://logging.apache.org/log4j/2.x/log4j-core/apidocs/org/apache/logging/log4j/core/net/Priority.html
新设施:https://logging.apache.org/log4j/log4j-2.8/log4j-core/apidocs/org/apache/logging/log4j/core/net/Facility.html https://logging.apache.org/log4j/log4j-2.8/log4j-core/apidocs/org/apache/logging/log4j/core/net/Facility.html
假设您正在谈论 Log4j 1Category.log(String, Priority, Object, Throwable) https://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/Category.html#log(java.lang.String,%20org.apache.log4j.Priority,%20java.lang.Object,%20java.lang.Throwable),看来这些Priority
类是相当(如果不是完全)不相关的。 Log4j 1的Priority
实际上是level(事实上它有一个子类Level
).
所以你必须看看 Log4j 2Logger https://logging.apache.org/log4j/2.x/log4j-api/apidocs/org/apache/logging/log4j/Logger.html类来查看是否有任何方法Level
参数匹配,但似乎没有相同的替代方案(除了logMessage https://logging.apache.org/log4j/2.x/log4j-api/apidocs/org/apache/logging/log4j/Logger.html#logMessage-org.apache.logging.log4j.Level-org.apache.logging.log4j.Marker-java.lang.String-java.lang.StackTraceElement-org.apache.logging.log4j.message.Message-java.lang.Throwable-也许吧,但这似乎是相当低的水平)。
但是,您应该检查是否targetClass
参数的参数callerFQCN
是实际需要的。看起来它的目的是找到 logger 方法的调用者,并且可能主要供扩展 Log4j 1 的日志库使用。除非您确实正在升级此类库,否则我会假设该方法被误用并且是常规 Log4j 2logger.debug(message)
也会做得同样好。不过,如果您能提供更多背景信息,那还是会有帮助的。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)