π Logging in Spring Boot
Logging is how your application writes messages during its execution β errors, info, debug messages, etc.
It helps developers track whatβs happening inside the app and troubleshoot problems.
π§ Logging in Spring Boot (Default)
Spring Boot uses SLF4J with Logback by default. You donβt need to add any extra dependency.
βοΈ How to Write Logs?
In your Java class:
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;public class MyService {
Β Β private static final Logger logger = LoggerFactory.getLogger(MyService.class);Β Β public void process() {
Β Β Β Β logger.info("Process started");
Β Β Β Β logger.debug("Debugging info");
Β Β Β Β logger.error("Something went wrong!");
Β Β }
}
βοΈ Configure Log Levels
You can set log levels in application.properties
: