Challenge - 5 Problems
Logger Mastery in Spring Boot
Get all challenges correct to earn this badge!
Test your skills under time pressure!
📝 Syntax
intermediate2:00remaining
Correct Logger Declaration in a Spring Boot Class
Which option correctly declares a logger in a Spring Boot class using SLF4J?
Spring Boot
public class MyService {
// Logger declaration here
}Attempts:
2 left
💡 Hint
Remember to use LoggerFactory and pass the class type for proper logger creation.
✗ Incorrect
Option B correctly uses LoggerFactory.getLogger with the class type and declares the logger as private static final, which is the recommended pattern in Spring Boot.
❓ component_behavior
intermediate2:00remaining
Logger Output Behavior in Spring Boot
Given a Spring Boot class with a logger declared as in option A of the previous question, what will be the output when calling logger.info("Hello World") if the logging level is set to WARN?
Spring Boot
private static final Logger logger = LoggerFactory.getLogger(MyService.class); public void greet() { logger.info("Hello World"); }
Attempts:
2 left
💡 Hint
Check the logging level hierarchy: ERROR > WARN > INFO > DEBUG.
✗ Incorrect
Since the logging level is set to WARN, INFO messages are ignored and not printed.
🔧 Debug
advanced2:00remaining
Identify the Logger Initialization Error
What error will occur when running this Spring Boot class code snippet?
Spring Boot
public class UserService { private static Logger logger = LoggerFactory.getLogger(); public void process() { logger.info("Processing user"); } }
Attempts:
2 left
💡 Hint
Check the LoggerFactory.getLogger method signature.
✗ Incorrect
LoggerFactory.getLogger() requires a parameter to specify the logger name or class. Omitting it causes a compilation error.
❓ state_output
advanced2:00remaining
Logger Instance Identity in Multiple Class Instances
If you create two instances of a Spring Boot class with a static logger declared as private static final Logger logger = LoggerFactory.getLogger(MyClass.class);, how many distinct logger instances exist in memory?
Spring Boot
public class MyClass { private static final Logger logger = LoggerFactory.getLogger(MyClass.class); public void log() { logger.info("Logging"); } } MyClass a = new MyClass(); MyClass b = new MyClass();
Attempts:
2 left
💡 Hint
Static fields belong to the class, not to instances.
✗ Incorrect
Static final logger means one logger instance per class, shared by all instances.
🧠 Conceptual
expert3:00remaining
Best Practice for Logger Declaration in Spring Boot
Which statement best explains why logger fields are declared as private static final in Spring Boot classes?
Attempts:
2 left
💡 Hint
Think about memory usage and immutability of logger objects.
✗ Incorrect
Declaring logger as private static final ensures one immutable logger per class, improving performance and consistency.