How do I tune my debug logging level statements for performance? I ask because my spring batch job can call roughly 50 of these logger.debug statements (doing more or less the same) a couple million times per job.
Query:
private final String updateIsUserFl = "update users "
+ "set flag = 'Y' "
+ "where name = ? and id = ? ";
Query Execution:
myJdbcTemplate.update(updateIsUserFl, name, id);
Logging Statements:
String debugQuery = updateIsUserFl.toString();
logger.debug(replace(debugQuery, "?", name, 1));
logger.debug(replace(debugQuery, "?", Integer.toString(id), 1));
Specific Questions:
So, basically, I want to print out the exact query passed in to my JdbcTemplate. Is there a better / less costly way than StringUtils.replace? Hopefully a little less heavy-handed as well (for maintainability sake).
Is calling toString on updateUserFl the right / efficient way to copy a final string object to do string manipulation?
Would wrapping this in an if logger.IsDebugEnabled check help or is slf4j already doing this for me?
Can I use logback / {} (in some way I can't think of) to help?
Is the log4j2, Java 8 (lambdas) an option I should consider? See: Avoid Log4j/Slf4j debug enabled checks