Use Apache Commons Logging instead of SLF4J.

Align logging API use with Spring Boot and Spring Cloud. Drop slf4j dependency from pom files.

Closes gh-84.
This commit is contained in:
Mark Paluch
2017-02-24 16:51:57 -05:00
parent c15d1181ee
commit 5fcd5694a4
7 changed files with 69 additions and 64 deletions

View File

@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
@@ -19,7 +21,13 @@
<artifactId>spring-vault-core</artifactId>
</dependency>
<dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<optional>true</optional>
@@ -35,11 +43,6 @@
<artifactId>spring-web</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>

View File

@@ -25,9 +25,7 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.extern.apachecommons.CommonsLog;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.http.HttpMethod;
@@ -54,7 +52,7 @@ import org.springframework.web.client.RestOperations;
*
* @author Mark Paluch
*/
@Slf4j
@CommonsLog
class LeasingVaultPropertySource extends VaultPropertySource implements DisposableBean {
private final LeaseRenewalScheduler leaseRenewal;
@@ -197,8 +195,8 @@ class LeasingVaultPropertySource extends VaultPropertySource implements Disposab
return null;
}
return Lease.of(leaseId, leaseDuration != null ? leaseDuration.longValue()
: 0, renewable);
return Lease.of(leaseId,
leaseDuration != null ? leaseDuration.longValue() : 0, renewable);
}
catch (HttpStatusCodeException e) {
throw new VaultException(String.format("Cannot renew lease: %s",
@@ -242,10 +240,9 @@ class LeasingVaultPropertySource extends VaultPropertySource implements Disposab
* a newer {@link Lease} for renewal, the previously registered renewal task will skip
* renewal.
*/
@CommonsLog
private static class LeaseRenewalScheduler {
private final Logger logger = LoggerFactory.getLogger(getClass());
private final TaskScheduler taskScheduler;
private final AtomicReference<Lease> currentLease = new AtomicReference<>();
@@ -273,8 +270,11 @@ class LeasingVaultPropertySource extends VaultPropertySource implements Disposab
void scheduleRenewal(final RenewLease renewLease, final Lease lease,
final int minRenewalSeconds, final int expiryThresholdSeconds) {
logger.debug("Scheduling renewal for lease {}, lease duration {}",
lease.getLeaseId(), lease.getLeaseDuration());
if (log.isDebugEnabled()) {
log.debug(String.format(
"Scheduling renewal for lease %s, lease duration %d",
lease.getLeaseId(), lease.getLeaseDuration()));
}
Lease currentLease = this.currentLease.get();
this.currentLease.set(lease);
@@ -283,32 +283,35 @@ class LeasingVaultPropertySource extends VaultPropertySource implements Disposab
cancelSchedule(currentLease);
}
ScheduledFuture<?> scheduledFuture = taskScheduler.schedule(
new Runnable() {
ScheduledFuture<?> scheduledFuture = taskScheduler.schedule(new Runnable() {
@Override
public void run() {
@Override
public void run() {
try {
schedules.remove(lease);
try {
if (LeaseRenewalScheduler.this.currentLease.get() != lease) {
logger.debug("Current lease has changed. Skipping renewal");
return;
}
schedules.remove(lease);
logger.debug("Renewing lease {}", lease.getLeaseId());
LeaseRenewalScheduler.this.currentLease.compareAndSet(
lease, renewLease.renewLease(lease));
}
catch (Exception e) {
logger.error("Cannot renew lease {}", lease.getLeaseId(),
e);
}
if (LeaseRenewalScheduler.this.currentLease.get() != lease) {
log.debug("Current lease has changed. Skipping renewal");
return;
}
},
new OneShotTrigger(getRenewalSeconds(lease, minRenewalSeconds,
expiryThresholdSeconds)));
if (log.isDebugEnabled()) {
log.debug(String.format("Renewing lease %s",
lease.getLeaseId()));
}
LeaseRenewalScheduler.this.currentLease.compareAndSet(lease,
renewLease.renewLease(lease));
}
catch (Exception e) {
log.error(String.format("Cannot renew lease %s",
lease.getLeaseId()), e);
}
}
}, new OneShotTrigger(
getRenewalSeconds(lease, minRenewalSeconds, expiryThresholdSeconds)));
schedules.put(lease, scheduledFuture);
}
@@ -317,8 +320,13 @@ class LeasingVaultPropertySource extends VaultPropertySource implements Disposab
ScheduledFuture<?> scheduledFuture = schedules.get(lease);
if (scheduledFuture != null) {
logger.debug("Canceling previously registered schedule for lease {}",
lease.getLeaseId());
if (log.isDebugEnabled()) {
log.debug(String.format(
"Canceling previously registered schedule for lease %s",
lease.getLeaseId()));
}
scheduledFuture.cancel(false);
}
}
@@ -339,8 +347,8 @@ class LeasingVaultPropertySource extends VaultPropertySource implements Disposab
private long getRenewalSeconds(Lease lease, int minRenewalSeconds,
int expiryThresholdSeconds) {
return Math.max(minRenewalSeconds, lease.getLeaseDuration()
- expiryThresholdSeconds);
return Math.max(minRenewalSeconds,
lease.getLeaseDuration() - expiryThresholdSeconds);
}
private boolean isLeaseRenewable(Lease lease) {
@@ -367,8 +375,8 @@ class LeasingVaultPropertySource extends VaultPropertySource implements Disposab
public Date nextExecutionTime(TriggerContext triggerContext) {
if (fired.compareAndSet(false, true)) {
return new Date(System.currentTimeMillis()
+ TimeUnit.SECONDS.toMillis(seconds));
return new Date(
System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(seconds));
}
return null;

View File

@@ -19,13 +19,13 @@ import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import lombok.extern.apachecommons.CommonsLog;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.core.env.PropertySource;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.util.Assert;
import lombok.extern.slf4j.Slf4j;
/**
* Extension to {@link LeasingVaultPropertySourceLocator} that creates
* {@link LeasingVaultPropertySource}s.
@@ -33,7 +33,7 @@ import lombok.extern.slf4j.Slf4j;
* @author Mark Paluch
* @see LeasingVaultPropertySource
*/
@Slf4j
@CommonsLog
class LeasingVaultPropertySourceLocator extends VaultPropertySourceLocator
implements DisposableBean {
@@ -97,8 +97,8 @@ class LeasingVaultPropertySourceLocator extends VaultPropertySourceLocator
((LeasingVaultPropertySource) propertySource).destroy();
}
catch (Exception e) {
log.warn("Cannot destroy property source {}",
propertySource.getName(), e);
log.warn(String.format("Cannot destroy property source %s",
propertySource.getName()), e);
}
}
}

View File

@@ -20,7 +20,7 @@ import java.util.Collection;
import java.util.List;
import lombok.experimental.UtilityClass;
import lombok.extern.slf4j.Slf4j;
import lombok.extern.apachecommons.CommonsLog;
/**
* Utility class to create {@link SecretBackendMetadata} from a
@@ -28,7 +28,7 @@ import lombok.extern.slf4j.Slf4j;
*
* @author Mark Paluch
*/
@Slf4j
@CommonsLog
@UtilityClass
class SecretBackendFactories {

View File

@@ -18,7 +18,7 @@ package org.springframework.cloud.vault.config;
import java.net.URI;
import java.util.Map;
import lombok.extern.slf4j.Slf4j;
import lombok.extern.apachecommons.CommonsLog;
import org.springframework.util.Assert;
import org.springframework.vault.VaultException;
@@ -34,7 +34,7 @@ import org.springframework.web.util.DefaultUriTemplateHandler;
* @author Mark Paluch
* @see VaultOperations
*/
@Slf4j
@CommonsLog
public class VaultConfigTemplate implements VaultConfigOperations {
private final DefaultUriTemplateHandler templateHandler = new DefaultUriTemplateHandler();
@@ -47,7 +47,8 @@ public class VaultConfigTemplate implements VaultConfigOperations {
* @param vaultOperations must not be {@literal null}.
* @param properties must not be {@literal null}.
*/
public VaultConfigTemplate(VaultOperations vaultOperations, VaultProperties properties) {
public VaultConfigTemplate(VaultOperations vaultOperations,
VaultProperties properties) {
Assert.notNull(vaultOperations, "VaultOperations must not be null!");
Assert.notNull(properties, "VaultProperties must not be null!");

View File

@@ -19,18 +19,18 @@ import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import lombok.extern.apachecommons.CommonsLog;
import org.springframework.core.env.EnumerablePropertySource;
import org.springframework.util.Assert;
import lombok.extern.slf4j.Slf4j;
/**
* A {@link EnumerablePropertySource} backed by {@link VaultConfigTemplate}.
*
* @author Spencer Gibb
* @author Mark Paluch
*/
@Slf4j
@CommonsLog
class VaultPropertySource extends EnumerablePropertySource<VaultConfigOperations> {
private final boolean failFast;

View File

@@ -25,7 +25,6 @@
<netty.version>4.1.6.Final</netty.version>
<okhttp.version>2.7.5</okhttp.version>
<okhttp3.version>3.5.0</okhttp3.version>
<slf4j.version>1.7.21</slf4j.version>
</properties>
<dependencyManagement>
@@ -140,12 +139,6 @@
<optional>true</optional>
</dependency>
<!-- Logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
</dependencies>
</dependencyManagement>