Bird
0
0

What is wrong with this logger declaration in a Spring Boot class?

medium📝 Debug Q7 of 15
Spring Boot - Logging
What is wrong with this logger declaration in a Spring Boot class?
private Logger logger = LoggerFactory.getLogger(getClass());
ALogger should be static and final
BgetClass() cannot be used here
CLoggerFactory.getLogger requires a String argument
DLogger cannot be private
Step-by-Step Solution
Solution:
  1. Step 1: Understand logger best practices

    Logger is usually declared static and final to avoid multiple instances per object.
  2. Step 2: Analyze given declaration

    Logger is non-static and non-final, which is not recommended.
  3. Final Answer:

    Logger should be static and final -> Option A
  4. Quick Check:

    Logger best practice = static final [OK]
Quick Trick: Declare logger as private static final for efficiency [OK]
Common Mistakes:
  • Omitting static and final modifiers
  • Thinking getClass() is invalid here
  • Assuming logger cannot be private

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes