Skip to content

Commit

Permalink
Consistently use commons logging
Browse files Browse the repository at this point in the history
Replace SLF4J with commons logging.
  • Loading branch information
philwebb committed May 20, 2020
1 parent e09e4db commit 7028251
Show file tree
Hide file tree
Showing 16 changed files with 93 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@
import java.time.temporal.TemporalAccessor;
import java.util.Optional;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.springframework.aop.support.AopUtils;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.core.log.LogMessage;
import org.springframework.data.domain.Auditable;
import org.springframework.data.domain.AuditorAware;
import org.springframework.data.mapping.PersistentEntity;
Expand All @@ -41,7 +42,7 @@
*/
public class AuditingHandler implements InitializingBean {

private static final Logger logger = LoggerFactory.getLogger(AuditingHandler.class);
private static final Log logger = LogFactory.getLog(AuditingHandler.class);

private final DefaultAuditableBeanWrapperFactory factory;

Expand Down Expand Up @@ -152,7 +153,8 @@ private <T> T touch(T target, boolean isNew) {
if (logger.isDebugEnabled()) {
Object defaultedNow = now.map(Object::toString).orElse("not set");
Object defaultedAuditor = auditor.map(Object::toString).orElse("unknown");
logger.debug("Touched {} - Last modification at {} by {}", target, defaultedNow, defaultedAuditor);
logger.debug(LogMessage.format("Touched %s - Last modification at %s by %s", target, defaultedNow,
defaultedAuditor));
}
return it.getBean();
}).orElse(target);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
import java.util.function.Predicate;
import java.util.stream.Collectors;

import org.slf4j.Logger;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import org.springframework.core.GenericTypeResolver;
import org.springframework.core.convert.converter.Converter;
Expand Down Expand Up @@ -62,7 +63,7 @@
*/
public class CustomConversions {

private static final Logger logger = org.slf4j.LoggerFactory.getLogger(CustomConversions.class);
private static final Log logger = LogFactory.getLog(CustomConversions.class);

private static final String READ_CONVERTER_NOT_SIMPLE = "Registering converter from %s to %s as reading converter although it doesn't convert from a store-supported type! You might want to check your annotation setup at the converter implementation.";

Expand Down Expand Up @@ -785,7 +786,7 @@ public String toString() {
/**
* Value object holding the actual {@link StoreConversions} and custom
* {@link Converter converters} configured for registration.
*
*
* @since 2.3
*/
protected static class ConverterConfiguration {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
*/
package org.springframework.data.crossstore;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import org.springframework.transaction.support.TransactionSynchronization;

public class ChangeSetBackedTransactionSynchronization implements TransactionSynchronization {

protected final Logger log = LoggerFactory.getLogger(getClass());
protected final Log logger = LogFactory.getLog(getClass());

private final ChangeSetPersister<Object> changeSetPersister;

Expand All @@ -38,22 +38,23 @@ public ChangeSetBackedTransactionSynchronization(ChangeSetPersister<Object> chan

@Override
public void afterCommit() {
this.log.debug("After Commit called for " + this.entity);
this.logger.debug("After Commit called for " + this.entity);
this.changeSetPersister.persistState(this.entity, this.entity.getChangeSet());
this.changeSetTxStatus = 0;
}

@Override
public void afterCompletion(int status) {
this.log.debug("After Completion called with status = " + status);
this.logger.debug("After Completion called with status = " + status);
if (this.changeSetTxStatus == 0) {
if (status == STATUS_COMMITTED) {
// this is good
this.log.debug("ChangedSetBackedTransactionSynchronization completed successfully for " + this.entity);
this.logger
.debug("ChangedSetBackedTransactionSynchronization completed successfully for " + this.entity);
}
else {
// this could be bad - TODO: compensate
this.log.error("ChangedSetBackedTransactionSynchronization failed for " + this.entity);
this.logger.error("ChangedSetBackedTransactionSynchronization failed for " + this.entity);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
import java.util.Map.Entry;
import java.util.stream.Collectors;

import org.slf4j.Logger;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import org.springframework.core.CollectionFactory;
import org.springframework.data.mapping.AccessOptions;
Expand Down Expand Up @@ -49,7 +50,7 @@
*/
class SimplePersistentPropertyPathAccessor<T> implements PersistentPropertyPathAccessor<T> {

private static final Logger logger = org.slf4j.LoggerFactory.getLogger(SimplePersistentPropertyPathAccessor.class);
private static final Log logger = LogFactory.getLog(SimplePersistentPropertyPathAccessor.class);

private final PersistentPropertyAccessor<T> delegate;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@
import java.util.stream.IntStream;
import java.util.stream.Stream;

import org.slf4j.Logger;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import org.springframework.beans.BeanUtils;
import org.springframework.core.log.LogMessage;
import org.springframework.core.type.MethodMetadata;
import org.springframework.data.type.MethodsMetadata;
import org.springframework.data.type.classreading.MethodsMetadataReader;
Expand Down Expand Up @@ -107,7 +109,7 @@ private static boolean hasDefaultGetter(PropertyDescriptor descriptor) {
*/
private static class PropertyDescriptorSource {

private static final Logger logger = org.slf4j.LoggerFactory.getLogger(PropertyDescriptorSource.class);
private static final Log logger = LogFactory.getLog(PropertyDescriptorSource.class);

private final Class<?> type;

Expand Down Expand Up @@ -199,7 +201,8 @@ private static Optional<MethodsMetadata> getMetadata(Class<?> type) {
return Optional.of(metadataReader.getMethodsMetadata());
}
catch (IOException e) {
logger.info("Couldn't read class metadata for {}. Input property calculation might fail!", type);
logger.info(LogMessage
.format("Couldn't read class metadata for %s. Input property calculation might fail!", type));
return Optional.empty();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@
import javax.enterprise.inject.spi.InjectionPoint;
import javax.enterprise.inject.spi.PassivationCapable;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import org.springframework.core.log.LogMessage;
import org.springframework.data.repository.config.CustomRepositoryImplementationDetector;
import org.springframework.data.repository.config.RepositoryFragmentConfiguration;
import org.springframework.data.repository.core.support.RepositoryComposition.RepositoryFragments;
Expand All @@ -63,7 +64,7 @@
*/
public abstract class CdiRepositoryBean<T> implements Bean<T>, PassivationCapable {

private static final Logger logger = LoggerFactory.getLogger(CdiRepositoryBean.class);
private static final Log logger = LogFactory.getLog(CdiRepositoryBean.class);

private static final CdiRepositoryConfiguration DEFAULT_CONFIGURATION = DefaultCdiRepositoryConfiguration.INSTANCE;

Expand Down Expand Up @@ -197,10 +198,11 @@ public final void initialize() {
public final T create(@SuppressWarnings("null") CreationalContext<T> creationalContext) {
T repoInstance = this.repoInstance;
if (repoInstance != null) {
logger.debug("Returning eagerly created CDI repository instance for {}.", this.repositoryType.getName());
logger.debug(LogMessage.format("Returning eagerly created CDI repository instance for %s.",
this.repositoryType.getName()));
return repoInstance;
}
logger.debug("Creating CDI repository bean instance for {}.", this.repositoryType.getName());
logger.debug(LogMessage.format("Creating CDI repository bean instance for %s.", this.repositoryType.getName()));
repoInstance = create(creationalContext, this.repositoryType);
this.repoInstance = repoInstance;
return repoInstance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@
import javax.enterprise.util.AnnotationLiteral;
import javax.inject.Qualifier;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.core.log.LogMessage;
import org.springframework.data.repository.NoRepositoryBean;
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.RepositoryDefinition;
Expand All @@ -53,7 +54,7 @@
*/
public abstract class CdiRepositoryExtensionSupport implements Extension {

private static final Logger logger = LoggerFactory.getLogger(CdiRepositoryExtensionSupport.class);
private static final Log logger = LogFactory.getLog(CdiRepositoryExtensionSupport.class);

private final Map<Class<?>, Set<Annotation>> repositoryTypes = new HashMap<>();

Expand Down Expand Up @@ -128,7 +129,7 @@ private Set<Annotation> getQualifiers(final Class<?> type) {
*/
void afterDeploymentValidation(@Observes AfterDeploymentValidation event, BeanManager manager) {
for (CdiRepositoryBean<?> bean : this.eagerRepositories) {
logger.debug("Eagerly instantiating CDI repository bean for {}.", bean.getBeanClass());
logger.debug(LogMessage.format("Eagerly instantiating CDI repository bean for %s.", bean.getBeanClass()));
bean.initialize();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
*/
package org.springframework.data.repository.config;

import org.slf4j.Logger;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.context.ApplicationListener;
Expand All @@ -32,8 +33,7 @@
*/
class DeferredRepositoryInitializationListener implements ApplicationListener<ContextRefreshedEvent>, Ordered {

private static final Logger logger = org.slf4j.LoggerFactory
.getLogger(DeferredRepositoryInitializationListener.class);
private static final Log logger = LogFactory.getLog(DeferredRepositoryInitializationListener.class);

private final ListableBeanFactory beanFactory;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
Expand All @@ -47,7 +47,7 @@
*/
class RepositoryBeanDefinitionBuilder {

private static final Logger logger = LoggerFactory.getLogger(RepositoryBeanDefinitionBuilder.class);
private static final Log logger = LogFactory.getLog(RepositoryBeanDefinitionBuilder.class);

private final BeanDefinitionRegistry registry;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
import java.util.Map;
import java.util.stream.Collectors;

import org.slf4j.Logger;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import org.springframework.beans.factory.config.DependencyDescriptor;
import org.springframework.beans.factory.parsing.BeanComponentDefinition;
Expand All @@ -38,6 +39,7 @@
import org.springframework.core.env.StandardEnvironment;
import org.springframework.core.io.ResourceLoader;
import org.springframework.core.io.support.SpringFactoriesLoader;
import org.springframework.core.log.LogMessage;
import org.springframework.data.repository.core.support.RepositoryFactorySupport;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
Expand All @@ -56,15 +58,15 @@
*/
public class RepositoryConfigurationDelegate {

private static final String REPOSITORY_REGISTRATION = "Spring Data {} - Registering repository: {} - Interface: {} - Factory: {}";
private static final String REPOSITORY_REGISTRATION = "Spring Data %s - Registering repository: %s - Interface: %s - Factory: %s";

private static final String MULTIPLE_MODULES = "Multiple Spring Data modules found, entering strict repository configuration mode!";

private static final String NON_DEFAULT_AUTOWIRE_CANDIDATE_RESOLVER = "Non-default AutowireCandidateResolver ({}) detected. Skipping the registration of LazyRepositoryInjectionPointResolver. Lazy repository injection will not be working!";
private static final String NON_DEFAULT_AUTOWIRE_CANDIDATE_RESOLVER = "Non-default AutowireCandidateResolver (%s) detected. Skipping the registration of LazyRepositoryInjectionPointResolver. Lazy repository injection will not be working!";

static final String FACTORY_BEAN_OBJECT_TYPE = "factoryBeanObjectType";

private static final Logger logger = org.slf4j.LoggerFactory.getLogger(RepositoryConfigurationDelegate.class);
private static final Log logger = LogFactory.getLog(RepositoryConfigurationDelegate.class);

private final RepositoryConfigurationSource configurationSource;

Expand Down Expand Up @@ -122,17 +124,17 @@ private static Environment defaultEnvironment(@Nullable Environment environment,
public List<BeanComponentDefinition> registerRepositoriesIn(BeanDefinitionRegistry registry,
RepositoryConfigurationExtension extension) {
if (logger.isInfoEnabled()) {
logger.info("Bootstrapping Spring Data {} repositories in {} mode.", extension.getModuleName(),
this.configurationSource.getBootstrapMode().name());
logger.info(LogMessage.format("Bootstrapping Spring Data %s repositories in %s mode.",
extension.getModuleName(), this.configurationSource.getBootstrapMode().name()));
}
extension.registerBeansForRoot(registry, this.configurationSource);
RepositoryBeanDefinitionBuilder builder = new RepositoryBeanDefinitionBuilder(registry, extension,
this.configurationSource, this.resourceLoader, this.environment);
List<BeanComponentDefinition> definitions = new ArrayList<>();
StopWatch watch = new StopWatch();
if (logger.isDebugEnabled()) {
logger.debug("Scanning for {} repositories in packages {}.", extension.getModuleName(),
this.configurationSource.getBasePackages().stream().collect(Collectors.joining(", ")));
logger.debug(LogMessage.format("Scanning for %s repositories in packages %s.", extension.getModuleName(),
this.configurationSource.getBasePackages().stream().collect(Collectors.joining(", "))));
}
watch.start();
Collection<RepositoryConfiguration<RepositoryConfigurationSource>> configurations = extension
Expand All @@ -153,8 +155,8 @@ public List<BeanComponentDefinition> registerRepositoriesIn(BeanDefinitionRegist
beanDefinition.setResourceDescription(configuration.getResourceDescription());
String beanName = this.configurationSource.generateBeanName(beanDefinition);
if (logger.isTraceEnabled()) {
logger.trace(REPOSITORY_REGISTRATION, extension.getModuleName(), beanName,
configuration.getRepositoryInterface(), configuration.getRepositoryFactoryBeanClassName());
logger.trace(LogMessage.format(REPOSITORY_REGISTRATION, extension.getModuleName(), beanName,
configuration.getRepositoryInterface(), configuration.getRepositoryFactoryBeanClassName()));
}
beanDefinition.setAttribute(FACTORY_BEAN_OBJECT_TYPE, configuration.getRepositoryInterface());
registry.registerBeanDefinition(beanName, beanDefinition);
Expand All @@ -164,8 +166,9 @@ public List<BeanComponentDefinition> registerRepositoriesIn(BeanDefinitionRegist
this.configurationSource.getBootstrapMode());
watch.stop();
if (logger.isInfoEnabled()) {
logger.info("Finished Spring Data repository scanning in {}ms. Found {} {} repository interfaces.",
watch.getLastTaskTimeMillis(), configurations.size(), extension.getModuleName());
logger.info(LogMessage.format(
"Finished Spring Data repository scanning in %sms. Found %s %s repository interfaces.",
watch.getLastTaskTimeMillis(), configurations.size(), extension.getModuleName()));
}
return definitions;
}
Expand All @@ -188,7 +191,7 @@ private static void potentiallyLazifyRepositories(Map<String, RepositoryConfigur
AutowireCandidateResolver resolver = beanFactory.getAutowireCandidateResolver();
if (!Arrays.asList(ContextAnnotationAutowireCandidateResolver.class, LazyRepositoryInjectionPointResolver.class)
.contains(resolver.getClass())) {
logger.warn(NON_DEFAULT_AUTOWIRE_CANDIDATE_RESOLVER, resolver.getClass().getName());
logger.warn(LogMessage.format(NON_DEFAULT_AUTOWIRE_CANDIDATE_RESOLVER, resolver.getClass().getName()));
return;
}
AutowireCandidateResolver newResolver = LazyRepositoryInjectionPointResolver.class.isInstance(resolver)
Expand Down Expand Up @@ -225,8 +228,7 @@ private boolean multipleStoresDetected() {
*/
static class LazyRepositoryInjectionPointResolver extends ContextAnnotationAutowireCandidateResolver {

private static final Logger logger = org.slf4j.LoggerFactory
.getLogger(LazyRepositoryInjectionPointResolver.class);
private static final Log logger = LogFactory.getLog(LazyRepositoryInjectionPointResolver.class);

private final Map<String, RepositoryConfiguration<?>> configurations;

Expand Down Expand Up @@ -256,7 +258,8 @@ protected boolean isLazy(DependencyDescriptor descriptor) {
}
boolean lazyInit = configuration.isLazyInit();
if (lazyInit) {
logger.debug("Creating lazy injection proxy for {}…", configuration.getRepositoryInterface());
logger.debug(LogMessage.format("Creating lazy injection proxy for %s…",
configuration.getRepositoryInterface()));
}
return lazyInit;
}
Expand Down
Loading

0 comments on commit 7028251

Please sign in to comment.