Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Logging Spring bean creation / dependency injection

I'm looking for a way to set up Log4j (or any other logger) so that I can see in log whenever Spring creates a bean or sets a bean property. Eg. something like this:

1:00:00 Creating bean Foo (Foo@ef5c94)
1:00:01 Creating bean Bar (Bar@147a87e)
1:00:02 Setting bean Foo (Foo@ef5c94) to Bar (Bar@147a87e)
(...)

Is this easily possible? I'm using Spring 2.5.6 (no choice there :/ ) and Log4j (version doesn't matter I expect).

like image 370
Ondrej Skalicka Avatar asked Jul 08 '11 12:07

Ondrej Skalicka


People also ask

Which dependency is used for log?

In the case of logging, the only mandatory dependency is Apache Commons Logging. We need to import it only when using Spring 4.

What is the role of dependencies for logging?

Logging is a very important dependency for Spring because a) it is the only mandatory external dependency, b) everyone likes to see some output from the tools they are using, and c) Spring integrates with lots of other tools all of which have also made a choice of logging dependency.


1 Answers

Looks like org.springframework.beans.factory.support.DefaultListableBeanFactory logger is the best you can get.

Also simply try turning on ALL logging level for the whole org.springframework - maybe you'll find something more useful.

like image 114
Tomasz Nurkiewicz Avatar answered Sep 23 '22 17:09

Tomasz Nurkiewicz