Logging
18 questions in 6 subtopics.
Logback and Log4j2
How do you switch a Spring Boot application from Logback to Log4j2, and what is the purpose oflogback-spring.xml compared to logback.xml?Teams use different logging backends, patterns and appenders. What would a logging standard for 100 services contain?Your company uses three log platforms after acquisitions. How would you decide on consolidation and what is the exit strategy if you later need to change vendor?Log levels and groups
Set DEBUG for the packagecom.acme.billing and the Hibernate SQL logger together under one name, and change it at runtime without a restart.Someone set the root logger to DEBUG in production through the loggers endpoint during an incident and forgot it. Disk filled and latency rose. What controls would you add?Logging frameworks in Java have changed several times: log4j, commons-logging, SLF4J, Logback, Log4j2, and the Log4Shell incident showed the risk. What long-term rules would you set for logging dependencies?Structured logging
How do you enable structured JSON logging in Spring Boot 3.4 or later, and which formats are built in?Why would you move from text logs to structured logs, and what fields would you require in each log event?Personal data appears in logs across many services and breaks your privacy policy. What would you put in place?MDC and correlation ids
Add a correlation id to every log line of a request in a Spring MVC application. Show where you set and clear it.Log lines from@Async methods and CompletableFuture callbacks miss the trace id, while lines from the request thread have it. Why, and how do you fix it?Incident investigations take hours because logs from 20 services cannot be correlated. How would you introduce correlation across the fleet?Log performance
Which of these is better and why:log.debug("Order " + order + " total " + total()); or log.debug("Order {} total {}", order, total());?A service spends 15 percent of CPU on logging and p99 latency spikes when the log collector is slow. What would you change?Log volume and cost grow faster than traffic in your organisation. How would you decide what to log, what to trace and what to measure, over the long term?Log files, appenders and patterns
Configure a Spring Boot service to write logs to /var/log/app/app.log, roll at 50 MB, keep 14 days and at most 2 GB in total, and change the console pattern to include the thread name.A service writes logs synchronously to a file on a network volume. When the volume slows down, request latency jumps and threads block in the appender. What do you change?Define where and how logs are written for services running on Kubernetes, VMs and a few legacy servers.No question matches these choices.