12

When I run my application, it stops when beans are initializing but doesn't show any logs entries. So I don't know what happened:

Log4j.properties

log4j.rootLogger=DEBUG, stdout, R

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
org.springframework=DEBUG
org.springframework.beans.factory.support=DEBUG
log4j.logger.org.springframework.beans.factory.support=DEBUG
log4j.logger.org.springframework.beans=DEBUG
log4j.category.org.springframework.beans.factory=DEBUG

log4j.logger.org.springframework=DEBUG

log4j.logger.org.hibernate.hql.ast.AST=info
log4j.logger.org.hibernate.tool.hbm2ddl=warn
log4j.logger.org.hibernate.cache=info
log4j.logger.org.hibernate.jdbc=debug
log4j.logger.org.hibernate.type=trace 
log4j.additivity.org.hibernate.SQL=false
log4j.logger.org.hibernate.transaction=debug
log4j.logger.java.sql.Statement=DEBUG

log4j.appender.stdout.layout.ConversionPattern=%d %t %C{1}- %m%n
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=${log4j.appender.R.File}
log4j.appender.R.MaxFileSize=2MB
log4j.appender.R.MaxBackupIndex=0
log4j.appender.R.Append=true
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%d %t (%l) - %m%n

I want to get something like:

"BeanName" initialized 
"BeanName" initialized
etc...

So then I would know where the initialization stopped. Is it possible to get such an output in the logs, when beans are initializing?

Stefan
  • 12,108
  • 5
  • 47
  • 66
Mateusz
  • 205
  • 1
  • 4
  • 11

2 Answers2

12

You need to set "org.springframework.beans.factory.support.DefaultListableBeanFactory" to debug level. The output looks something like this:

... - Creating instance of bean ...
... - Finished creating instance of bean  ...

Update:

Add this to log4j.properties:

log4j.logger.org.springframework.beans.factory.support.DefaultListableBeanFactory=DEBUG

Keep in mind that Spring is using the commons-logging framework, therefore these lines will not appear in your Log4J logs. To redirect them use SLF4J. Add slf4j-api.jar, jcl-over-slf4j.jar, slf4j-log4j12.jar and log4j.jar to your lib directory and remove commons-logging.jar from it.

Stefan
  • 12,108
  • 5
  • 47
  • 66
  • I already have all of this dependencies in my pom.xml and commons-logging has `provided` Maybe i have to add this log4j.properties somewhere? – Mateusz Aug 13 '14 at 12:35
  • Commons-logging must be excluded. And remove 'org.springframework=DEBUG' and 'org.springframework.beans.factory.support=DEBUG' lines from the properties file. – Stefan Aug 13 '14 at 12:38
  • I done everything what you say but still nothing i have log4j.properties looks like you want and it's in src/main/resources/properties/ directory. – Mateusz Aug 13 '14 at 12:55
  • 2
    Put it in src/main/resources/ only – Stefan Aug 13 '14 at 12:57
  • After move this file to src/main/resources it works ! – Mateusz Aug 13 '14 at 12:59
3

add to your log4j xml (check if you already have one with lavel ERROR, change it either INFO or DEBUG

<logger name="org.springframework">
        <level value="INFO" />
</logger>
Pravin Bansal
  • 4,315
  • 1
  • 28
  • 19