SLF4J with Logback - SirajChaudhary/comprehensive-example-on-microservices-using-spring-boot-with-spring-cloud GitHub Wiki
SLF4J with Logback (Faccade Design Pattern)
- SLF4J, Logback are part of spring-boot-starter-web dependency.
- Spring Boot supports different logging providers such as Java Util Logging, Log4j2 and Logback based on configuration provided
- Logback is default logging framework for spring boot.
- Logback herarchy levels are ALL -> TRACE -> DEBUG -> INFO -> WARN -> ERROR -> FATAL -> OFF
- We'll use SLF4J with Logback implementation (Faccade Design Pattern).
Step1: Add Logback logging properties in applicaiton.yml
# If we don't define following properties it picks default properties i.e. logging.level=info
logging:
level:
root: DEBUG
# LOGGING FOR SPECIFIC PACKAGE
com:
airport:
checkin:
controller: TRACE
pattern:
# console: '"%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n"'
file: '"%d{yyyy-MM-dd HH:mm:ss} - %msg%n"'
file:
name: src/main/resources/logs/checkin-service-logfile.log
max-size: 10MB
clean-history-on-start: 'true'
Step2: Log the logs using SLF4J APIs. Example