Convert Logback Spring Properties to JSON
Transform Logback-related Spring Boot logging properties into JSON for understanding the logging hierarchy and configuration.
Detailed Explanation
Logback via Spring Boot Properties
While Logback itself uses XML for configuration (logback-spring.xml), Spring Boot exposes many Logback settings through application.properties. These properties control log levels, file output, patterns, and rolling policies.
Example Properties
# Log Levels
logging.level.root=INFO
logging.level.com.example.service=DEBUG
logging.level.com.example.repository=TRACE
logging.level.org.springframework.web=WARN
logging.level.org.hibernate=ERROR
# File Output
logging.file.name=logs/application.log
logging.file.path=/var/log/myapp
logging.file.max-size=50MB
logging.file.max-history=30
logging.file.total-size-cap=1GB
# Console Pattern
logging.pattern.console=%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(%-5level) %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n
# File Pattern
logging.pattern.file=%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level [%t] %logger{39} : %m%n
Nested JSON Output
The nested JSON clearly shows the logging level hierarchy:
{
"logging": {
"level": {
"root": "INFO",
"com": {
"example": {
"service": "DEBUG",
"repository": "TRACE"
}
},
"org": {
"springframework": { "web": "WARN" },
"hibernate": "ERROR"
}
},
"file": {
"name": "logs/application.log",
"maxSize": "50MB",
"maxHistory": 30
}
}
}
This tree view makes it easy to understand which packages have which log level, especially in large projects with dozens of package-specific log level overrides.
Use Case
Visualizing the logging level hierarchy across packages in a Spring Boot application, comparing logging configuration between environments, or documenting the complete logging setup for operational handover.