How to create log4j Logger using Spring XML configuration?

How to create log4j Logger using Spring XML configuration?

I would like to do something like this so that I can insert the registrar into other instances:

<bean id="logger" class="org.apache.log4j.Logger">
    <property name="logName" value="my.Logger" />
</bean>
+5
source share
1 answer

You can build beans using static methods using the factory -method attribute. Thus, for log4j we can use the static method Logger.getLogger()to build a bean:

<bean id="logger" class="org.apache.log4j.Logger" factory-method="getLogger">
    <constructor-arg type="java.lang.String" value="my.Logger" />
</bean>
+6
source

All Articles