Hello
I have a simple POJO application (no web or J2EE application) and need to configure Log4J through Spring so I can use properties injection.
For example if you configure Hibernate through Spring, you can use properties injection, like this:
<property name="driverClassName">
<value>${db.driverClass}</value>
</property>
Spring will inject the value of the db.driverClass property wherever it finds the ${db.driverClass} expression.
Is it possible to do the same thing with the Log4J configuration?.
I have the following Log4J.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd" >
<log4j:configuration>
<appender name="general.appender" class="org.apache.log4j.FileAppender">
<param name="Append" value="true"/>
<param name="File" value="application.log"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d [%p] %m (%F:%L)%n"/>
</layout>
</appender>
<root>
<level value ="INFO"/>
<appender-ref ref="general.appender"/>
</root>
</log4j:configuration>
I have a property that stores the location for the log file and need this property to be injected in the log4j configuration, like this:
<param name="File" value="${log.path}/application.log"/>
I know Log4J itself can do this kind of injection if log.path were a system property, but that's not the case. The log.path property is a normal property loaded by Spring.
Can Spring help with this property injection?.
Any help would be appreciated.
Thanks


Reply With Quote
