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

Issue: SPR-16946
This commit is contained in:
Juergen Hoeller 2018-08-10 15:45:46 +02:00
parent def6fbba89
commit aebb2d52e0
13 changed files with 41 additions and 37 deletions

View File

@ -414,9 +414,9 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport
TargetSource ts = tsc.getTargetSource(beanClass, beanName);
if (ts != null) {
// Found a matching TargetSource.
if (logger.isDebugEnabled()) {
logger.debug("TargetSourceCreator [" + tsc +
" found custom TargetSource for bean with name '" + beanName + "'");
if (logger.isTraceEnabled()) {
logger.trace("TargetSourceCreator [" + tsc +
"] found custom TargetSource for bean with name '" + beanName + "'");
}
return ts;
}
@ -522,10 +522,10 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport
}
}
}
if (logger.isDebugEnabled()) {
if (logger.isTraceEnabled()) {
int nrOfCommonInterceptors = commonInterceptors.length;
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");
}

View File

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

View File

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

View File

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

View File

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

View File

@ -10,8 +10,6 @@
</Appenders>
<Loggers>
<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" />
<Root level="error">
<AppenderRef ref="Console" />

View File

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

View File

@ -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");
* 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.transaction.support.DefaultTransactionDefinition;
import org.springframework.util.StringUtils;
/**
* Spring's common transaction attribute implementation.
@ -82,7 +83,7 @@ public class DefaultTransactionAttribute extends DefaultTransactionDefinition im
* to process this specific transaction.
* @since 3.0
*/
public void setQualifier(String qualifier) {
public void setQualifier(@Nullable String qualifier) {
this.qualifier = qualifier;
}
@ -141,7 +142,7 @@ public class DefaultTransactionAttribute extends DefaultTransactionDefinition im
*/
protected final StringBuilder getAttributeDescription() {
StringBuilder result = getDefinitionDescription();
if (this.qualifier != null) {
if (StringUtils.hasText(this.qualifier)) {
result.append("; '").append(this.qualifier).append("'");
}
return result;

View File

@ -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");
* 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
* 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() {
return this.debug;

View File

@ -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");
* you may not use this file except in compliance with the License.
@ -56,7 +56,7 @@ import static org.mockito.BDDMockito.*;
public class ScheduledAndTransactionalAnnotationIntegrationTests {
@Before
public void setUp() {
public void assumePerformanceTests() {
Assume.group(TestGroup.PERFORMANCE);
}
@ -165,7 +165,7 @@ public class ScheduledAndTransactionalAnnotationIntegrationTests {
}
@Bean
public PersistenceExceptionTranslationPostProcessor peTranslationPostProcessor() {
public static PersistenceExceptionTranslationPostProcessor peTranslationPostProcessor() {
return new PersistenceExceptionTranslationPostProcessor();
}
}

View File

@ -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

View File

@ -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>

View File

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