[slf4j-dev] Feature Request - adding Supplier<String> for org.slf4j.Logger interface

Nikita Sheremet nikita.sheremet.java.developer at gmail.com
Tue Oct 31 06:48:34 CET 2017


IDEA
Original idea is here - https://github.com/MicroUtils/kotlin-logging

The idea is to pass Supplier<String> to debug (info, error, etc.)
methods instead of template string and object varargs array.

KOTLIN (just for example)
In kotlin it looks like that:

logger.debug { "Some $expensive message!" }

So you pass just function and framework decides evaluate for message
producing it or not.

JAVA
in java it may looks like that:

logger.debug(() -> "Code which produce heavy log message"));

or

logger.debug(() -> {
    return "Code which produce heavy log message"
}));

E.g. we put isDebugEnabled call into framework and make code cleaner.

IMPLEMENTATION
It is necessary to add counterpart method with Supplier<String>
argument for all methods that have final String s, final Object...
objects arguments in signature.

DISADVANATAGES
For now I can see only one - slf4j framework will require java 8 version


Do you agree to add such feature?
Feel free to ask any me any questions.


More information about the slf4j-dev mailing list