Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

slf4j logging syntax

Tags:

logging

slf4j

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);
like image 674
m0therway Avatar asked Aug 31 '12 20:08

m0therway


1 Answers

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.

like image 63
Tomasz Nurkiewicz Avatar answered Nov 22 '22 12:11

Tomasz Nurkiewicz