Skip to content

@InjectLogger

excilys edited this page Mar 22, 2011 · 5 revisions

@InjectLogger

What for?

Feed up with copy/pasting (and sometimes forgetting to change MyClass) to declare a slf4j logger?

  private Logger logger = LoggerFactory.getLogger(MyClass.class)

How ?

Just follow these 2 steps :

1° Annotate your logger

  @InjectLogger
  private Logger logger;

2° Declare the BeanPostProcessor into your Spring context :

  <bean class="com.excilys.utils.spring.log.slf4j.BeanWithLogger" />

or

  <import resource="classpath:context/applicationContext-spring-log.xml" />

Limitations

As the logger is injected after the target bean is instanciated, don't try to log anything in constructors... In this case, revert to manual instanciation.

Clone this wiki locally