Skip to content

Instantly share code, notes, and snippets.

@odornauf
Last active July 5, 2018 05:17
Show Gist options
  • Save odornauf/7b82904141d3f6316e70e690dd01ed65 to your computer and use it in GitHub Desktop.
Save odornauf/7b82904141d3f6316e70e690dd01ed65 to your computer and use it in GitHub Desktop.
Clean log with Apache Log4j2 and Java 8 Lambdas
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