简体   繁体   中英

How do I create a log4j Logger using Spring XML configuration?

How do I create a log4j Logger using Spring XML configuration?

I would like to do something like this so I can inject the logger into other instances:

<bean id="logger" class="org.apache.log4j.Logger">
    <property name="logName" value="my.Logger" />
</bean>

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM