spring-projects / spring-projects/spring-boot
Support for registering a custom Logback Converter conversion rule
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 81.5k
- Forks
- 42.7k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 65
Description
In order to register a Custom Logback Converter through conversion rules it is currently required to provide a custom logback.xml file. It is also impossible to provide custom conversion rules through other auto configuration means such as a Spring Boot Auto configuration or some other spring factory mechanism.
The use case for this is to provide some additional context information to the logging. e.g. the currently authenticated user when logging.
If this is something that the Spring Boot team is willing to accept I am more than happy to work on providing an extension mechanism for this.
I have 2 approaches in mind (they can be complimentary to one another).
Using a Customizer
public interface LoggerContextCustomizer {
void customize(LoggerContext context);
}
This can be applied in the DefaultLogbackConfinguration prior to applying the Spring defaults:
The LoggerContextCustomizer customizers won't be exposed as beans, but they would be registered in a similar way as the org.springframework.boot.diagnostics.FailureAnalyzer in the spring.factories.
Using properties
This approach could use a property to register custom conversion rules
e.g.
logging.logback.conversion-rule.<conversionWord>=<converterClass>
This approach is more limiting that the one using a customizer and it does close the gap to Log4J 2.
This approach might also be slightly less invasive and would only be targeted towards conversion rules.
Such an approach is not needed for Log4J 2 since Log4J 2 has a completely different mechanism of registering custom converters and the only thing we need to do there is to write our converter with the recommended approach by Log4J 2 and the converter keys will be automatically be available to be used in the log pattern
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with DefaultLogbackConfiguration.java at the referenced customization point, then compare the proposed registration approach with FailureAnalyzer entries in spring.factories. Review the Logback custom conversion rule use case and decide which extension mechanism the project will support. Done means custom conversion rules can be registered without a custom logback.xml file.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring-boot
- Domain
- observability-sre
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100