Spring / Spring Boot 4 Basics Interview Questions
How does Spring Boot 4 handle logging configuration?
Spring Boot 4 auto-configures Logback as the default logging framework (with SLF4J as the facade). Log4j2 and JUL are also supported. Boot 4 enhances structured logging for production observability.
# Logging configuration in application.yml: logging: level: root: INFO # global default level com.example.service: DEBUG # package-specific level org.springframework.security: WARN # reduce security noise org.hibernate.SQL: DEBUG # log SQL statements org.hibernate.orm.jdbc.bind: TRACE # log SQL parameters file: name: /var/log/order-service/app.log logback: rollingpolicy: max-file-size: 100MB max-history: 30 pattern: console: "%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n" file: "%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} [%X{traceId},%X{spanId}] - %msg%n" // Structured logging (JSON) for production / log aggregation: logging: structured: format: console: ecs # Elastic Common Schema file: logstash # Logstash JSON format # Output: machine-readable JSON logs for ELK stack // Using SLF4J in application code: @Service public class OrderService { private static final Logger log = LoggerFactory.getLogger(OrderService.class); // Or with Lombok: // @Slf4j // public class OrderService { public Order createOrder(CreateOrderRequest req) { log.debug("Creating order for product: {}", req.productId()); Order order = repo.save(new Order(req)); log.info("Order created successfully: id={}, product={}", order.id(), order.productId()); return order; } } // Change log level at runtime via Actuator: // POST /actuator/loggers/com.example.service // Body: {"configuredLevel": "DEBUG"}
More Related questions...