I'm migrating from log4j 1.x to 2.x and we have a properties file "foo.properties" which we read in spring's applicationContext.xml
and turn into system properties:
<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="foo" value="classpath:META-INF/properties/foo.properties" />
</bean>
<bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetObject">
<bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetClass" value="java.lang.System" />
<property name="targetMethod" value="getProperties" />
</bean>
</property>
<property name="targetMethod" value="putAll" />
<property name="arguments">
<util:properties>
<prop key="x.y.z">${x.y.z}</prop>
<prop key="a.b.c">${a.b.c}</prop>
...
</util:properties>
</property>
</bean>
I would expect to be able now to reference x.y.z
in log4j2.xml like <RollingFile name="rollingFile" fileName="${sys:x.y.z}">
, however this doesn't work with 2.x. With 1.x ${x.y.z}
works fine.
Previously, we had this code in applicationContext.xml
to initialize log4j:
<bean id="log4jInitialization"
class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetClass" value="org.springframework.util.Log4jConfigurer" />
<property name="targetMethod" value="initLogging" />
<property name="arguments">
<list>
<value>classpath:log4jMain.xml</value>
</list>
</property>
</bean>
But this was removed because it does not apply for 2.x, which may have broken something. How can I get log4j2 to lookup a system property set by Spring?