Announcement Announcement Module
Collapse
No announcement yet.
Is there a way to inject the logger instance in a bean configuration? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Is there a way to inject the logger instance in a bean configuration?

    I'm a newbie in Spring and I was just wondering if there's a way to set the code below as a bean property?

    private static org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(<<Name of Class>>.class.getName());

    The intention is to avoid having to code this line in every class.


    Thanks.

  • #2
    Originally posted by glicup
    I'm a newbie in Spring and I was just wondering if there's a way to set the code below as a bean property?

    private static org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(<<Name of Class>>.class.getName());

    The intention is to avoid having to code this line in every class.


    Thanks.
    Even if there is you would have to do it for each class, as each class needs a separate Logger. Why not just set up an Eclipse template that plugs in a Logger for you when you create a new class ?

    Comment


    • #3
      Actually there is a FactoryBean (org.sf.beans.factory.config.CommonsLogFactoryBean ) that injects log instances; however, as Paul mentioned what you want is actually a template that should be applied when the class is created (something that is probably already supported by your IDE).

      Comment

      Working...
      X