Best way to define a Logger instance in a class

I am looking through some code and have seen many ways to define a log instance in a class. Some of them

protected static final Logger LOG
final Logger LOG

in few

protected static final Logger LOG
final Logger LOG

it confused me, as some of them defined it as static final and protected, where, as some defined it as final, few declared a variable in all caps, and some in normal form.

Can anyone understand what is appropriate for an announcement or its personal choice or a specific project?

+3
source share
4 answers

I always go for

private static final Logger logger.

, , ( ). .

( //) , .

protected, - . - , .

+3

- , slf4j jcabi-log:

Logger.debug(this, "some variable = %s", value);
+1

private static final Logger logger = Logger.getLogger(MyClass.class).

:

private final Logger logger = Logger.getLogger(getClass())

, / . - , Logger.getLogger(One.class) Two, .

0

, :

  • : LOG.
  • : LOG.
  • final, protected static final.

,

LOG LOG . , . final Java , . , , - ; .

protected Java , , , , .

Java, /, , .

,

protected static final Logger LOG , LOG , , , , , .

final Logger LOG , LOG , - , .

, private static final logger LOG.

Java , :

Java

, .

0

All Articles