Bird
0
0

Which of the following is the correct way to declare a logger in a Spring Boot class using SLF4J?

easy📝 Syntax Q3 of 15
Spring Boot - Logging
Which of the following is the correct way to declare a logger in a Spring Boot class using SLF4J?
Aprivate static final Logger logger = LoggerFactory.getLogger(MyClass.class);
BLogger logger = new Logger();
CLogger logger = LoggerFactory.createLogger();
Dprivate Logger logger = LoggerFactory.getLogger();
Step-by-Step Solution
Solution:
  1. Step 1: Recall SLF4J logger declaration syntax

    The standard way is to use LoggerFactory.getLogger with the class name.
  2. Step 2: Check each option for correctness

    Only private static final Logger logger = LoggerFactory.getLogger(MyClass.class); matches the correct syntax with static final and class reference.
  3. Final Answer:

    private static final Logger logger = LoggerFactory.getLogger(MyClass.class); -> Option A
  4. Quick Check:

    Logger declaration = LoggerFactory.getLogger with class [OK]
Quick Trick: Use LoggerFactory.getLogger(ClassName.class) for logger [OK]
Common Mistakes:
  • Missing static final keywords
  • Wrong LoggerFactory method
  • Not passing class to getLogger

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes