Results 1 to 2 of 2

Thread: log4j configuration with JavaConfig

Hybrid View

  1. #1
    Join Date
    May 2008
    Posts
    7

    Default log4j configuration with JavaConfig

    I have a standalone (not web) application using JavaConfig and when I start the app I get the following log entries:

    2009/01/16 20:59:36:529 GMT [INFO] JavaConfigApplicationContext - Refreshing org.springframework.config.java.context.JavaConfig ApplicationContext@4c2d0479: display name [org.springframework.config.java.context.JavaConfig ApplicationContext@4c2d0479]; startup
    date [Fri Jan 16 20:59:36 GMT 2009]; root of context hierarchy
    2009/01/16 20:59:36:667 GMT [INFO] JavaConfigApplicationContext - Bean factory for application context [org.springframework.config.java.context.JavaConfig ApplicationContext@4c2d0479]: org.springframework.beans.factory.support.DefaultL istableBeanFactory@4d16318b
    2009/01/16 20:59:37:054 GMT [INFO] ConfigurationModelBeanDefinitionReader - Registering PUBLIC bean definition for @Configuration ... etc.

    I have tried to control the logging with the following @Configuration class:

    @Configuration(defaultLazy = Lazy.FALSE)
    public class Log4jConfig {
    @Bean(lazy = Lazy.FALSE)
    public MethodInvokingFactoryBean log4jInitialization() {
    final MethodInvokingFactoryBean bean =
    new MethodInvokingFactoryBean();
    bean.setTargetClass(Log4jConfigurer.class);
    bean.setTargetMethod("initLogging");
    bean.setArguments(new Object[] {"spring-log4j.xml"});

    return bean;
    }
    }

    ... but it doesn't seem to work - the app still spews the same log entries as before. The @Bean corresponds to the bean definition XML that supposedly controls log4j settings in a Spring XML configuration.

    Any ideas?

    Thanks in advance.

  2. #2
    Join Date
    Apr 2007
    Posts
    307

    Default

    Looks like a chicken-and-egg problem. The output that you're seeing is log4j output that happens before that @Bean gets processed. You can suppress or otherwise influence this by configuring the usual log4j.properties or log4j.xml in your classpath.
    Chris Beams
    Spring Framework committer, VMware
    http://github.com/cbeams

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •