I have been working on java 7 so far and recently moved to java-8, one thing which was surprising is that you can add methods in java-8 interfaces.
So far so good....loved this new stuff!
Now, my problem is that logging
is an essential part of any development but seems lombok.extern.slf4j
won't let you add log
stuffs in by interface methods as it is only allowed on classes
and enums
.
How do you log
your interface methods (if by lombok
or is this the only way?? ) ? Or is interface methods not supposed to be logged? what am i missing here?
P.S : At present i am working with System.out.println
.... yeah...thats noob :)
Currently Lombok @Slf4j
annotation is not supported on interfaces,
but it can be circumvented like this
public interface MyInterface
{
@Slf4j
final class LogHolder
{}
default void action() {
LogHolder.log.error("Error TEST");
}
}
you can add logger to your interface manually, but your logger will be public:
public interface SomeInterface {
Logger log = LoggerFactory.getLogger(SomIface.class);
default void action() {
log.info("TEST");
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With