I’ve got 3 developers on a project who have different styles when writing to logs. Which of these variations is best?
LOG.info("error = {}", errmsg);
LOG.info("error = ", errmsg);
LOG.info("error = " + errmsg);
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Correct and best.
This is most likely wrong. Unless
errmsgis an exception, it will never be logged.This one is not performing as good as first. You’ll run
Stringconcatenation every time you hit this line while in first case variable replacement occurs only if statement will actually be logged.Some time ago I blogged about different logging syntaxes in slf4j.