Enhance the configuration of log4j2 (xml), support Profile-specific Configuration (<SpringProfile>
), consistent with logback extension.
Spring Boot currently only enhances the Logback (XML) configuration to support the
I copied the code in Log4j2 XML to parse the XML configuration and created a new SpringBootXmlConfiguration to support the
Compatibility issues with rewriting the Log4j2 parsing code:
- I just copied the
XmlConfiguration
code directly from Log4j2, adding very little code and making no big changes like formatting. If there is an update to Log4j2, it is easy to rewrite the parsing class and update it accordingly. - The
XmlConfiguration
class in Log4j2 was last updated in June 2019, with no updates between [2.12.0,2.14.1] and the default dependent version of Log4j2 in Springboot (master) is 2.14.1
To sum up, there is no risk in this kind of enhancement
Comment From: kongwu-
My local build has passed
Comment From: wilkinsona
Thanks for the proposal.
I'm afraid that I'm not keen on copying Log4j 2's XmlConfiguration
into Spring Boot and then modifying it, regardless of how stable the code may be. Even if we were comfortable with the approach, we'd also need to do the same for JsonConfiguration
and YamlConfiguration
as Boot supports yaml and json configuration in addition to XML.
If you would like to see Spring Boot's Log4j2 integration support springProfile and springProperty as they do with Logback, I think it should be done via some officially supported plug points in Log4j2. https://github.com/spring-projects/spring-boot/issues/22149 is tracking possibly switching from Logback to Log4j2 and the Log4j team have offered their help. We can use that issue to explore things.