如果 lombok.log.fieldIsStatic 设置为 false,则记录静态方法

Logging static methods if lombok.log.fieldIsStatic is set to false

我加入了一个使用 lombok @Slf4j 进行日志记录但具有以下配置的新项目:

lombok.log.fieldIsStatic=false

这使我无法在静态方法中使用 Lombok 的记录器。我没有得到关于为什么这样配置的解释,但我不允许更改它。显然我可以用静态方法的旧时尚方式来做到这一点,例如

private static final Logger LOG = LoggerFactory.getLogger(MyClass.class); 

但我喜欢带注释的方法。所以我的问题是是否有可能同时使用这两种方法,即在不更改 lombok.log.fieldIsStatic 属性 值的情况下对静态和非静态方法使用 Lombok 的日志记录方法。

感谢您的关注。

来自the docs

Configuration files are hierarchical: Any configuration setting applies to all source files in that directory, and all source files in subdirectories, but configuration settings closer to the source file take precedence.

因此您可以创建第二个 Lombok 配置文件,它是一个模块独有的,或者甚至可能只是一个包,它在根级别覆盖 属性 以将其重置为静态。

否则没有

I didn't get an explanation on why it is configured like this, but I am not allowed to change it

这听起来像是一个文化问题。我完全赞成遵循既定的先例,但前提是有人能够并且愿意证明为什么选择它。