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);
LOG.info("error = {}", errmsg);
Correct and best.
LOG.info("error = ", errmsg);
This is most likely wrong. Unless errmsg
is an exception, it will never be logged.
LOG.info("error = " + errmsg);
This one is not performing as good as first. You'll run String
concatenation 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With