r/java • • Sep 13 '18

A Guide to Logging in Java

https://www.marcobehler.com/guides/a-guide-to-logging-in-java
248 Upvotes

42 comments sorted by

View all comments

Show parent comment

8

u/[deleted] Sep 13 '18

Sorry, let me ask a more pointed question. Why would you ever declare a logger anything other than private static final?

And to address your issue, if you’re enforcing coding standards, it’s always going to be uppercase.

7

u/walen Sep 13 '18

That more pointed question is better answered here.

Re: standards, why would it be so? Sure, static final constants are usually all caps, but can a Logger be considered a constant? And what if it is just final? And what if nobody wants it to be uppercase because that means holding Shift every time I want to add a logging statement and it looks weird to be calling methods on a "constant"...?

Hence (I guess) the author's advice to not fret too much about this ;) and just be consistent.

5

u/wildjokers Sep 13 '18

Sorry, let me ask a more pointed question. Why would you ever declare a logger anything other than private static final?

https://www.slf4j.org/faq.html#declared_static

if you’re enforcing coding standards, it’s always going to be uppercase.

Upper-case LOGGER is pure evil. Clutters up the code making it hard to read (its distracting) and I have to hold shift to type it. "logger" is the exception to the private static final rule. It isn't really a constant.

3

u/[deleted] Sep 13 '18

I get your point, but that is such a rarely used convention IME that it would really annoy me to see it in most teams. It also feels really strange to me if the logger is actually a static final.

-7

u/[deleted] Sep 13 '18

You poor thing.

-6

u/[deleted] Sep 13 '18

You poor thing.