如何阻止Spring的默认输出?

时间:2012-05-03 16:31:12

标签: java spring logging

我是Spring的新手。当我运行Spring批处理应用程序时,我希望只能看到“Hello World!”,而是获得以下其他详细信息 -

May 03, 2012 12:28:42 PM    org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@4e660b27: startup date [Thu May 03 12:28:42 EDT 2012]; root of context hierarchy
May 03, 2012 12:28:42 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [helloWorldJob.xml]
May 03, 2012 12:28:43 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [MEMORY-JOBREPOSITORY.xml]
May 03, 2012 12:28:44 PM org.springframework.beans.factory.support.DefaultListableBeanFactory registerBeanDefinition
INFO: Overriding bean definition for bean 'helloWorldJob': replacing [Generic bean: class [org.springframework.batch.core.configuration.xml.SimpleFlowFactoryBean]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] with [Generic bean: class [org.springframework.batch.core.configuration.xml.JobParserJobFactoryBean]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null]
May 03, 2012 12:28:44 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@63dfb24d: defining beans [jobRepository,jobRepository-transactionManager,jobLauncher,hello,world,org.springframework.batch.core.scope.internalStepScope,org.springframework.beans.factory.config.CustomEditorConfigurer,org.springframework.batch.core.configuration.xml.CoreNamespacePostProcessor,step0,step1,helloWorldJob]; root of factory hierarchy
May 03, 2012 12:28:44 PM org.springframework.aop.framework.DefaultAopProxyFactory 
INFO: CGLIB2 available: proxyTargetClass feature enabled
May 03, 2012 12:28:44 PM org.springframework.batch.core.launch.support.SimpleJobLauncher afterPropertiesSet
INFO: No TaskExecutor has been set, defaulting to synchronous executor.
May 03, 2012 12:28:44 PM org.springframework.batch.core.launch.support.SimpleJobLauncher$1 run
INFO: Job: [FlowJob: [name=helloWorldJob]] launched with the following parameters: [{time=11:06AM}]
May 03, 2012 12:28:44 PM org.springframework.batch.core.job.SimpleStepHandler handleStep
INFO: Executing step: [step0]
HelloMay 03, 2012 12:28:44 PM org.springframework.batch.core.job.SimpleStepHandler handleStep
INFO: Executing step: [step1]
 World!May 03, 2012 12:28:44 PM org.springframework.batch.core.launch.support.SimpleJobLauncher$1 run
INFO: Job: [FlowJob: [name=helloWorldJob]] completed with the following parameters: [{time=11:06AM}] and the following status: [COMPLETED]
May 03, 2012 12:28:44 PM org.springframework.context.support.AbstractApplicationContext doClose
INFO: Closing org.springframework.context.support.ClassPathXmlApplicationContext@4e660b27: startup date [Thu May 03 12:28:42 EDT 2012]; root of context hierarchy
May 03, 2012 12:28:44 PM org.springframework.beans.factory.support.DefaultSingletonBeanRegistry destroySingletons
INFO: Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@63dfb24d: defining beans [jobRepository,jobRepository-transactionManager,jobLauncher,hello,world,org.springframework.batch.core.scope.internalStepScope,org.springframework.beans.factory.config.CustomEditorConfigurer,org.springframework.batch.core.configuration.xml.CoreNamespacePostProcessor,step0,step1,helloWorldJob]; root of factory hierarchy

如何防止这些额外的东西出现?谢谢。

其他信息-log4j.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">

  <appender name="appender" class="org.apache.log4j.FileAppender">
    <param name="File" value="helloWorld-Log.txt"/>
    <param name="Append" value="false"/>
    <layout class="org.apache.log4j.PatternLayout">
      <param name="ConversionPattern" value="%d [%t] %p - %m%n"/>
    </layout>
  </appender>
  <appender name="ConsoleAppender" class="org.apache.log4j.ConsoleAppender">
    <layout class="org.apache.log4j.SimpleLayout"/>
  </appender>
  <root>
    <priority value ="ERROR"/>
    <appender-ref ref="ConsoleAppender"/>
  </root>

</log4j:configuration>

1 个答案:

答案 0 :(得分:2)

您可以switch to Log4J loggingset the log level to ERROR or FATAL。 这样就可以停用所有非错误日志记录。

但Dave Newton是对的:听起来确实不错。