Last active
July 5, 2018 05:17
-
-
Save odornauf/7b82904141d3f6316e70e690dd01ed65 to your computer and use it in GitHub Desktop.
Clean log with Apache Log4j2 and Java 8 Lambdas
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import lombok.extern.log4j.Log4j2; | |
@Log4j2 | |
public class CSysFormular { | |
public void preJava8() { | |
String parameter1 = "test"; | |
// Log only if log level equal or above debug | |
if (logger.isDebugEnabled()) { | |
logger.debug("Logentry Parameters {} {} ", parameter1, costlyOperation()); | |
} | |
} | |
public void Java8() { | |
String parameter1 = "test"; | |
//parameter1 and costlyOperation are only evaluated if loglevel equal or above debug | |
logger.debug("Logentry Parameters {} {} ", () -> parameter1, ()->costlyOperation()); | |
} | |
public String costlyOperation() { | |
return ""; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment