简体   繁体   中英

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:

lombok.log.fieldIsStatic=false

This prevents me from using Lombok's logger in static methods. 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

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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