当在程序中出现异常时,jvm在默认情况下会将异常信息打印到控制台。如下:
D:\springlog>java -Djava.util.logging.config.file=log4j.properties -Djava.util.logging.manager=org.apache.log4j.LogManager -Djava.ext.dirs=. com.LogTest
log4j:ERROR Could not find value for key log4j.appender.Console
log4j:ERROR Could not instantiate appender named "Console".
Exception in thread "main" java.lang.ArithmeticException: / by zero
at com.PrintLogService.printLog(PrintLogService.java:12)
at com.LogTest.main(LogTest.java:18)
而生成的日志文件中却没有相应的异常信息,异常代码如下:
public void printLog(){
logger.info("*************方法开始****************");
int i = 1 / 0;
System.out.println(i);
logger.info("*************方法结束****************");
}
文件信息如下:
2016-04-05 14:34:28,434 [main] DEBUG [org.springframework.core.env.PropertySourcesPropertyResolver] - getProperty("spring.liveBeansView.mbeanDomain", String)
2016-04-05 14:34:28,435 [main] DEBUG [org.springframework.core.env.PropertySourcesPropertyResolver] - Searching for key 'spring.liveBeansView.mbeanDomain' in [systemProperties]
2016-04-05 14:34:28,435 [main] DEBUG [org.springframework.core.env.PropertySourcesPropertyResolver] - Searching for key 'spring.liveBeansView.mbeanDomain' in [systemEnvironment]
2016-04-05 14:34:28,435 [main] DEBUG [org.springframework.core.env.SystemEnvironmentPropertySource] - PropertySource [systemEnvironment] does not contain 'spring.liveBeansView.mbeanDomain'
2016-04-05 14:34:28,435 [main] DEBUG [org.springframework.core.env.SystemEnvironmentPropertySource] - PropertySource [systemEnvironment] does not contain 'spring_liveBeansView_mbeanDomain'
2016-04-05 14:34:28,436 [main] DEBUG [org.springframework.core.env.SystemEnvironmentPropertySource] - PropertySource [systemEnvironment] does not contain 'SPRING.LIVEBEANSVIEW.MBEANDOMAIN'
2016-04-05 14:34:28,436 [main] DEBUG [org.springframework.core.env.SystemEnvironmentPropertySource] - PropertySource [systemEnvironment] does not contain 'SPRING_LIVEBEANSVIEW_MBEANDOMAIN'
2016-04-05 14:34:28,436 [main] DEBUG [org.springframework.core.env.PropertySourcesPropertyResolver] - Could not find key 'spring.liveBeansView.mbeanDomain' in any property source. Returning [null]
2016-04-05 14:34:28,436 [main] DEBUG [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Returning cached instance of singleton bean 'lifecycleProcessor'
2016-04-05 14:34:28,436 [main] DEBUG [org.springframework.context.support.ClassPathXmlApplicationContext] - Publishing event in org.springframework.context.support.ClassPathXmlApplicationContext@7402d14a: org.springframework.context.event.ContextStartedEvent[source=org.springframework.context.support.ClassPathXmlApplicationContext@7402d14a: startup date [Tue Apr 05 14:34:28 CST 2016]; root of context hierarchy]
2016-04-05 14:34:28,436 [main] DEBUG [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Returning cached instance of singleton bean 'printlog'
2016-04-05 14:34:28,436 [main] INFO [com.PrintLogService] - *************方法开始****************