Browse Source

Logging refinements for transaction and cache processing (debug/trace)

Issue: SPR-16946
pull/1925/head
Juergen Hoeller 8 years ago
parent
commit
aebb2d52e0
  1. 10
      spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/AbstractAutoProxyCreator.java
  2. 8
      spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/BeanFactoryAdvisorRetrievalHelper.java
  3. 9
      spring-beans/src/main/java/org/springframework/beans/factory/annotation/InjectionMetadata.java
  4. 4
      spring-context/src/main/java/org/springframework/cache/interceptor/AbstractFallbackCacheOperationSource.java
  5. 4
      spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassBeanDefinitionReader.java
  6. 2
      spring-core/src/test/resources/log4j2-test.xml
  7. 4
      spring-tx/src/main/java/org/springframework/transaction/interceptor/AbstractFallbackTransactionAttributeSource.java
  8. 7
      spring-tx/src/main/java/org/springframework/transaction/interceptor/DefaultTransactionAttribute.java
  9. 4
      spring-tx/src/main/java/org/springframework/transaction/support/DefaultTransactionStatus.java
  10. 6
      src/test/java/org/springframework/scheduling/annotation/ScheduledAndTransactionalAnnotationIntegrationTests.java
  11. 5
      src/test/resources/log4j.properties
  12. 13
      src/test/resources/log4j2-test.xml
  13. 2
      src/test/resources/testlog4j.properties

10
spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/AbstractAutoProxyCreator.java

@ -414,9 +414,9 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport
TargetSource ts = tsc.getTargetSource(beanClass, beanName); TargetSource ts = tsc.getTargetSource(beanClass, beanName);
if (ts != null) { if (ts != null) {
// Found a matching TargetSource. // Found a matching TargetSource.
if (logger.isDebugEnabled()) { if (logger.isTraceEnabled()) {
logger.debug("TargetSourceCreator [" + tsc + logger.trace("TargetSourceCreator [" + tsc +
" found custom TargetSource for bean with name '" + beanName + "'"); "] found custom TargetSource for bean with name '" + beanName + "'");
} }
return ts; return ts;
} }
@ -522,10 +522,10 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport
} }
} }
} }
if (logger.isDebugEnabled()) { if (logger.isTraceEnabled()) {
int nrOfCommonInterceptors = commonInterceptors.length; int nrOfCommonInterceptors = commonInterceptors.length;
int nrOfSpecificInterceptors = (specificInterceptors != null ? specificInterceptors.length : 0); int nrOfSpecificInterceptors = (specificInterceptors != null ? specificInterceptors.length : 0);
logger.debug("Creating implicit proxy for bean '" + beanName + "' with " + nrOfCommonInterceptors + logger.trace("Creating implicit proxy for bean '" + beanName + "' with " + nrOfCommonInterceptors +
" common interceptors and " + nrOfSpecificInterceptors + " specific interceptors"); " common interceptors and " + nrOfSpecificInterceptors + " specific interceptors");
} }

8
spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/BeanFactoryAdvisorRetrievalHelper.java

@ -82,8 +82,8 @@ public class BeanFactoryAdvisorRetrievalHelper {
for (String name : advisorNames) { for (String name : advisorNames) {
if (isEligibleBean(name)) { if (isEligibleBean(name)) {
if (this.beanFactory.isCurrentlyInCreation(name)) { if (this.beanFactory.isCurrentlyInCreation(name)) {
if (logger.isDebugEnabled()) { if (logger.isTraceEnabled()) {
logger.debug("Skipping currently created advisor '" + name + "'"); logger.trace("Skipping currently created advisor '" + name + "'");
} }
} }
else { else {
@ -96,8 +96,8 @@ public class BeanFactoryAdvisorRetrievalHelper {
BeanCreationException bce = (BeanCreationException) rootCause; BeanCreationException bce = (BeanCreationException) rootCause;
String bceBeanName = bce.getBeanName(); String bceBeanName = bce.getBeanName();
if (bceBeanName != null && this.beanFactory.isCurrentlyInCreation(bceBeanName)) { if (bceBeanName != null && this.beanFactory.isCurrentlyInCreation(bceBeanName)) {
if (logger.isDebugEnabled()) { if (logger.isTraceEnabled()) {
logger.debug("Skipping advisor '" + name + logger.trace("Skipping advisor '" + name +
"' with dependency on currently created bean: " + ex.getMessage()); "' with dependency on currently created bean: " + ex.getMessage());
} }
// Ignore: indicates a reference back to the bean we're trying to advise. // Ignore: indicates a reference back to the bean we're trying to advise.

9
spring-beans/src/main/java/org/springframework/beans/factory/annotation/InjectionMetadata.java

@ -70,8 +70,8 @@ public class InjectionMetadata {
if (!beanDefinition.isExternallyManagedConfigMember(member)) { if (!beanDefinition.isExternallyManagedConfigMember(member)) {
beanDefinition.registerExternallyManagedConfigMember(member); beanDefinition.registerExternallyManagedConfigMember(member);
checkedElements.add(element); checkedElements.add(element);
if (logger.isDebugEnabled()) { if (logger.isTraceEnabled()) {
logger.debug("Registered injected element on class [" + this.targetClass.getName() + "]: " + element); logger.trace("Registered injected element on class [" + this.targetClass.getName() + "]: " + element);
} }
} }
} }
@ -83,10 +83,9 @@ public class InjectionMetadata {
Collection<InjectedElement> elementsToIterate = Collection<InjectedElement> elementsToIterate =
(checkedElements != null ? checkedElements : this.injectedElements); (checkedElements != null ? checkedElements : this.injectedElements);
if (!elementsToIterate.isEmpty()) { if (!elementsToIterate.isEmpty()) {
boolean debug = logger.isDebugEnabled();
for (InjectedElement element : elementsToIterate) { for (InjectedElement element : elementsToIterate) {
if (debug) { if (logger.isTraceEnabled()) {
logger.debug("Processing injected element of bean '" + beanName + "': " + element); logger.trace("Processing injected element of bean '" + beanName + "': " + element);
} }
element.inject(target, beanName, pvs); element.inject(target, beanName, pvs);
} }

4
spring-context/src/main/java/org/springframework/cache/interceptor/AbstractFallbackCacheOperationSource.java vendored

@ -98,8 +98,8 @@ public abstract class AbstractFallbackCacheOperationSource implements CacheOpera
else { else {
Collection<CacheOperation> cacheOps = computeCacheOperations(method, targetClass); Collection<CacheOperation> cacheOps = computeCacheOperations(method, targetClass);
if (cacheOps != null) { if (cacheOps != null) {
if (logger.isDebugEnabled()) { if (logger.isTraceEnabled()) {
logger.debug("Adding cacheable method '" + method.getName() + "' with attribute: " + cacheOps); logger.trace("Adding cacheable method '" + method.getName() + "' with attribute: " + cacheOps);
} }
this.attributeCache.put(cacheKey, cacheOps); this.attributeCache.put(cacheKey, cacheOps);
} }

4
spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassBeanDefinitionReader.java

@ -161,8 +161,8 @@ class ConfigurationClassBeanDefinitionReader {
this.registry.registerBeanDefinition(definitionHolder.getBeanName(), definitionHolder.getBeanDefinition()); this.registry.registerBeanDefinition(definitionHolder.getBeanName(), definitionHolder.getBeanDefinition());
configClass.setBeanName(configBeanName); configClass.setBeanName(configBeanName);
if (logger.isDebugEnabled()) { if (logger.isTraceEnabled()) {
logger.debug("Registered bean definition for imported class '" + configBeanName + "'"); logger.trace("Registered bean definition for imported class '" + configBeanName + "'");
} }
} }

2
spring-core/src/test/resources/log4j2-test.xml

@ -10,8 +10,6 @@
</Appenders> </Appenders>
<Loggers> <Loggers>
<Logger name="org.springframework.core" level="info" /> <Logger name="org.springframework.core" level="info" />
<Logger name="org.springframework.core.convert" level="warn" />
<Logger name="org.springframework.core.GenericTypeResolver" level="warn" />
<Logger name="org.springframework.util" level="warn" /> <Logger name="org.springframework.util" level="warn" />
<Root level="error"> <Root level="error">
<AppenderRef ref="Console" /> <AppenderRef ref="Console" />

4
spring-tx/src/main/java/org/springframework/transaction/interceptor/AbstractFallbackTransactionAttributeSource.java

@ -119,8 +119,8 @@ public abstract class AbstractFallbackTransactionAttributeSource implements Tran
if (txAttr instanceof DefaultTransactionAttribute) { if (txAttr instanceof DefaultTransactionAttribute) {
((DefaultTransactionAttribute) txAttr).setDescriptor(methodIdentification); ((DefaultTransactionAttribute) txAttr).setDescriptor(methodIdentification);
} }
if (logger.isDebugEnabled()) { if (logger.isTraceEnabled()) {
logger.debug("Adding transactional method '" + methodIdentification + "' with attribute: " + txAttr); logger.trace("Adding transactional method '" + methodIdentification + "' with attribute: " + txAttr);
} }
this.attributeCache.put(cacheKey, txAttr); this.attributeCache.put(cacheKey, txAttr);
} }

7
spring-tx/src/main/java/org/springframework/transaction/interceptor/DefaultTransactionAttribute.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -18,6 +18,7 @@ package org.springframework.transaction.interceptor;
import org.springframework.lang.Nullable; import org.springframework.lang.Nullable;
import org.springframework.transaction.support.DefaultTransactionDefinition; import org.springframework.transaction.support.DefaultTransactionDefinition;
import org.springframework.util.StringUtils;
/** /**
* Spring's common transaction attribute implementation. * Spring's common transaction attribute implementation.
@ -82,7 +83,7 @@ public class DefaultTransactionAttribute extends DefaultTransactionDefinition im
* to process this specific transaction. * to process this specific transaction.
* @since 3.0 * @since 3.0
*/ */
public void setQualifier(String qualifier) { public void setQualifier(@Nullable String qualifier) {
this.qualifier = qualifier; this.qualifier = qualifier;
} }
@ -141,7 +142,7 @@ public class DefaultTransactionAttribute extends DefaultTransactionDefinition im
*/ */
protected final StringBuilder getAttributeDescription() { protected final StringBuilder getAttributeDescription() {
StringBuilder result = getDefinitionDescription(); StringBuilder result = getDefinitionDescription();
if (this.qualifier != null) { if (StringUtils.hasText(this.qualifier)) {
result.append("; '").append(this.qualifier).append("'"); result.append("; '").append(this.qualifier).append("'");
} }
return result; return result;

4
spring-tx/src/main/java/org/springframework/transaction/support/DefaultTransactionStatus.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -132,7 +132,7 @@ public class DefaultTransactionStatus extends AbstractTransactionStatus {
/** /**
* Return whether the progress of this transaction is debugged. This is used * Return whether the progress of this transaction is debugged. This is used
* by AbstractPlatformTransactionManager as an optimization, to prevent repeated * by AbstractPlatformTransactionManager as an optimization, to prevent repeated
* calls to logger.isDebug(). Not really intended for client code. * calls to {@code logger.isDebug()}. Not really intended for client code.
*/ */
public boolean isDebug() { public boolean isDebug() {
return this.debug; return this.debug;

6
src/test/java/org/springframework/scheduling/annotation/ScheduledAndTransactionalAnnotationIntegrationTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -56,7 +56,7 @@ import static org.mockito.BDDMockito.*;
public class ScheduledAndTransactionalAnnotationIntegrationTests { public class ScheduledAndTransactionalAnnotationIntegrationTests {
@Before @Before
public void setUp() { public void assumePerformanceTests() {
Assume.group(TestGroup.PERFORMANCE); Assume.group(TestGroup.PERFORMANCE);
} }
@ -165,7 +165,7 @@ public class ScheduledAndTransactionalAnnotationIntegrationTests {
} }
@Bean @Bean
public PersistenceExceptionTranslationPostProcessor peTranslationPostProcessor() { public static PersistenceExceptionTranslationPostProcessor peTranslationPostProcessor() {
return new PersistenceExceptionTranslationPostProcessor(); return new PersistenceExceptionTranslationPostProcessor();
} }
} }

5
src/test/resources/log4j.properties

@ -1,5 +0,0 @@
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%d{HH:mm:ss,SSS} [%c] - %m%n
log4j.rootCategory=WARN, console

13
src/test/resources/log4j2-test.xml

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
</Console>
</Appenders>
<Loggers>
<Root level="debug">
<AppenderRef ref="Console" />
</Root>
</Loggers>
</Configuration>

2
src/test/resources/testlog4j.properties

@ -1,2 +0,0 @@
log4j.rootCategory=DEBUG, mock
log4j.appender.mock=org.springframework.util.MockLog4jAppender
Loading…
Cancel
Save