简体   繁体   English

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

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

I joined a new project which uses lombok @Slf4j for logging but has the following configuration:我加入了一个使用@Slf4j进行日志记录的新项目,但具有以下配置:

lombok.log.fieldIsStatic=false

This prevents me from using Lombok's logger in static methods.这使我无法在 static 方法中使用 Lombok 的记录器。 I didn't get an explanation on why it is configured like this, but I am not allowed to change it.我没有得到解释为什么它是这样配置的,但我不能改变它。 Obviously I can do it the old fashion way for static methods, eg显然我可以用 static 方法的老式方法来做,例如

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

but I love the annotated approach.但我喜欢带注释的方法。 So my question is whether it is possible to have it both ways, ie use Lombok's logging approach for both static and non-static methods without changing the lombok.log.fieldIsStatic property value.所以我的问题是是否可以同时使用它,即在不更改lombok.log.fieldIsStatic属性值的情况下,对 static 和非静态方法使用 Lombok 的日志记录方法。

Thank you for your attention.感谢您的关注。

From 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 .配置文件是分层的:任何配置设置都适用于该目录中的所有源文件,以及子目录中的所有源文件,但更接近源文件的配置设置优先

So you could create a second Lombok config file which is exclusive to one module, or maybe even just one package, which overrides the property at the root level to reset it back to static.因此,您可以创建一个专用于一个模块的第二个 Lombok 配置文件,或者甚至可能只创建一个 package,它会覆盖根级别的属性以将其重置回 static。

Otherwise, no.否则,不行。

I didn't get an explanation on why it is configured like this, but I am not allowed to change it我没有得到解释为什么它是这样配置的,但我不能改变它

This sounds like a cultural issue.这听起来像是一个文化问题。 I am all for following an established precedent, but only if someone can and will justify why it was chosen.我完全赞成遵循既定的先例,但前提是有人能够并且愿意证明为什么选择它。

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

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