File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Spring and the fly likes inject log4j logger Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "inject log4j logger" Watch "inject log4j logger" New topic

inject log4j logger

zb cong
Ranch Hand

Joined: Jan 14, 2002
Posts: 416
there is a logger field in my java class, which is log4j logger type, i want to inject it by spring, but i am not sure how to config the applicationConext for this logger. following does not work, because the Logger has not default constructor.

<bean id="logger" class="org.apache.log4j.Logger"/>

who can help? how to config the spring to inject log4j logger attribute?

T. Huy Nguyen
Ranch Hand

Joined: Nov 02, 2010
Posts: 57
Haven't tried, but I think you'll need to create a bean factory to create lo4J instances.

Just curious, why do you need to inject a log4j logger instead of creating an static one?

My material for SCJP (2008), SCWCD (2010), SCBCD (2010). About me
zb cong
Ranch Hand

Joined: Jan 14, 2002
Posts: 416
yes , the bean factory works, as for why we inject the logger, you need to as the designer :-)
I agree. Here's the link:
subject: inject log4j logger
jQuery in Action, 3rd edition