简体   繁体   English

Log4J 1.2文档中的奇怪演员

[英]Strange cast in Log4J 1.2 docs

I was looking through Log4J docs and stumbled at the following in the description of Logger#setLevel() (inherited from Category ) method: 我正在查看Log4J文档,并在Logger#setLevel() (继承自Category )方法的描述中偶然发现以下内容:

If you are passing any of Level.DEBUG , Level.INFO , Level.WARN , Level.ERROR , Level.FATAL as a parameter, you need to case them as Level . 如果您将Level.DEBUGLevel.INFOLevel.WARNLevel.ERRORLevel.FATAL中的任何一个作为参数Level.ERRORLevel.FATAL需要将它们视为Level As in 如在

 logger.setLevel((Level) Level.DEBUG); 

Is there any reason behind such requirement? 这种要求背后有什么理由吗?

Am I missing something here? 我在这里错过了什么吗?

This seems like a documentation error that was introduced when Category.setPriority() was deprecated and Category.setLevel() was added in the 1.2 version. 这似乎是当被引入一个文档的错误Category.setPriority()已被废弃和Category.setLevel()在1.2版本中加入。

This is how the setPriority method originally looked like in jakarta-log4j-1.1.3 : 这就是setPriority方法最初在jakarta-log4j-1.1.3样子:

/**
 Set the priority of this Category.
 <p>Null values are admitted.
*/
public void setPriority(Priority priority) {
    this.priority = priority;
}

Looking at the source for setPriority in log4j-1.2.17 , we can see that when the method was deprecated, a narrowing cast to Level was added: 查看log4j-1.2.17 setPriority的源代码,我们可以看到,当该方法被弃用时,添加了一个缩小到Level log4j-1.2.17

/**
 Set the level of this Category.
 <p>Null values are admitted.
 @deprecated Please use {@link #setLevel} instead.
*/
public void setPriority(Priority priority) {
   this.level = (Level) priority;
}

So, it seems like an implementation detail of setPriority somehow slipped into the JavaDocs of the new setLevel method. 因此,似乎setPriority的实现细节以某种方式滑入了新setLevel方法的JavaDocs。 Obviously, the documentation makes no sense as the cast is not required. 显然,文档没有意义,因为不需要强制转换。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM