Performance: Log levels (TRACE, DEBUG, INFO, WARN, ERROR)
Log levels affect application runtime performance and resource usage by controlling the amount of logging output generated.
if (logger.isTraceEnabled()) { logger.trace("Detailed trace info: {}", expensiveMethod()); }
logger.trace("Detailed trace info: {}", expensiveMethod());| Pattern | CPU Usage | I/O Overhead | Memory Usage | Verdict |
|---|---|---|---|---|
| Unconditional TRACE logging with expensive calls | High (always runs expensive code) | High (many logs written) | High (string creation) | [X] Bad |
| Conditional TRACE logging with isTraceEnabled() | Low (skips expensive code) | Low (logs only when enabled) | Low (avoids string creation) | [OK] Good |
| INFO level logging for key events | Moderate | Moderate | Moderate | [!] OK |
| ERROR level logging only for errors | Low | Low | Low | [OK] Good |
application.properties for Spring Boot?logging.level.root to set root log level.logger.debug("Debug message");
logger.info("Info message");
logger.error("Error message");logging.level.com.example=DEBUG in application.properties, but DEBUG messages from com.example.service do not appear. What is the most likely cause?com.example.repository package but keep the rest of the application logging at WARN level. Which application.properties configuration achieves this?logging.level.root=WARN to limit logs globally to warnings and errors.logging.level.com.example.repository=TRACE to get detailed logs only for that package.Pass the test and this pattern moves unknown