From 2e19e4ae50e34e8db541aba87d3a15cf99669948 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niccol=C3=B2=20Maltoni?= Date: Wed, 27 Nov 2024 09:37:35 +0100 Subject: [PATCH] feat: drop CarapaceLogger  Conflicts:  carapace-server/src/main/java/org/carapaceproxy/core/Listeners.java  carapace-server/src/main/java/org/carapaceproxy/core/ProxyRequestsManager.java --- .../api/CertificatesResource.java | 2 +- .../org/carapaceproxy/core/Listeners.java | 26 +++--- .../core/ProxyRequestsManager.java | 89 ++++++++++++------- .../carapaceproxy/core/RequestsLogger.java | 5 +- .../core/RuntimeServerConfiguration.java | 5 -- .../core/StaticContentsManager.java | 2 +- .../carapaceproxy/core/TrustStoreManager.java | 15 ++-- .../launcher/ZooKeeperMainWrapper.java | 3 +- .../cache/CacheByteBufMemoryUsageMetric.java | 8 +- .../server/cache/CaffeineCacheImpl.java | 2 +- .../DynamicCertificatesManager.java | 2 +- .../server/certificates/Route53Client.java | 6 +- .../server/certificates/ocsp/OcspUtils.java | 18 ++-- .../org/carapaceproxy/user/FileUserRealm.java | 3 +- .../carapaceproxy/utils/CarapaceLogger.java | 56 ------------ .../src/main/resources/logback.xml | 4 +- .../java/org/carapaceproxy/RawClientTest.java | 6 -- .../org/carapaceproxy/RealBackendsTest.java | 3 - .../backends/ChunkedEncodingResponseTest.java | 2 - .../backends/RestartEndpointTest.java | 2 - 20 files changed, 107 insertions(+), 152 deletions(-) delete mode 100644 carapace-server/src/main/java/org/carapaceproxy/utils/CarapaceLogger.java diff --git a/carapace-server/src/main/java/org/carapaceproxy/api/CertificatesResource.java b/carapace-server/src/main/java/org/carapaceproxy/api/CertificatesResource.java index f32da745c..facc2de01 100644 --- a/carapace-server/src/main/java/org/carapaceproxy/api/CertificatesResource.java +++ b/carapace-server/src/main/java/org/carapaceproxy/api/CertificatesResource.java @@ -210,7 +210,7 @@ private static void fillCertificateBean( } bean.setStatus(certificateStateToString(state)); } catch (GeneralSecurityException | IOException ex) { - LOG.error("Unable to read Keystore for certificate {}. Reason: {}", certificate.getId(), ex); + LOG.error("Unable to read Keystore for certificate {}", certificate.getId(), ex); } } diff --git a/carapace-server/src/main/java/org/carapaceproxy/core/Listeners.java b/carapace-server/src/main/java/org/carapaceproxy/core/Listeners.java index 6e53e0dbf..9666aa37c 100644 --- a/carapace-server/src/main/java/org/carapaceproxy/core/Listeners.java +++ b/carapace-server/src/main/java/org/carapaceproxy/core/Listeners.java @@ -65,7 +65,6 @@ import org.carapaceproxy.server.config.ConfigurationNotValidException; import org.carapaceproxy.server.config.NetworkListenerConfiguration; import org.carapaceproxy.server.config.SSLCertificateConfiguration; -import org.carapaceproxy.utils.CarapaceLogger; import org.carapaceproxy.utils.CertificatesUtils; import org.carapaceproxy.utils.PrometheusUtils; import org.slf4j.Logger; @@ -202,19 +201,19 @@ void reloadConfiguration(RuntimeServerConfiguration newConfiguration) throws Int currentConfiguration = newConfiguration; try { - for (EndpointKey hostport : listenersToStop) { + for (final EndpointKey hostport : listenersToStop) { LOG.info("Stopping {}", hostport); stopListener(hostport); } - for (EndpointKey hostport : listenersToRestart) { + for (final EndpointKey hostport : listenersToRestart) { LOG.info("Restart {}", hostport); stopListener(hostport); NetworkListenerConfiguration newConfigurationForListener = currentConfiguration.getListener(hostport); bootListener(newConfigurationForListener); } - for (EndpointKey hostport : listenersToStart) { + for (final EndpointKey hostport : listenersToStart) { LOG.info("Starting {}", hostport); NetworkListenerConfiguration newConfigurationForListener = currentConfiguration.getListener(hostport); bootListener(newConfigurationForListener); @@ -293,10 +292,13 @@ protected SslHandler newSslHandler(SslContext context, ByteBufAllocator allocato }) .httpRequestDecoder(option -> option.maxHeaderSize(currentConfiguration.getMaxHeaderSize())) .handle((request, response) -> { // Custom request-response handling - if (CarapaceLogger.isLoggingDebugEnabled()) { - CarapaceLogger.debug("Receive request " + request.uri() - + " From " + request.remoteAddress() - + " Timestamp " + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd-HH-mm-ss.SSS"))); + if (LOG.isDebugEnabled()) { + LOG.debug( + "Receive request {} From {} Timestamp {}", + request.uri(), + request.remoteAddress(), + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd-HH-mm-ss.SSS")) + ); } ListeningChannel channel = listeningChannels.get(hostPort); @@ -309,12 +311,14 @@ protected SslHandler newSslHandler(SslContext context, ByteBufAllocator allocato // response compression if (currentConfiguration.getResponseCompressionThreshold() >= 0) { - CarapaceLogger.debug("Response compression enabled with min size = {0} bytes for listener {1}", - currentConfiguration.getResponseCompressionThreshold(), hostPort + LOG.debug( + "Response compression enabled with min size = {} bytes for listener {}", + currentConfiguration.getResponseCompressionThreshold(), + hostPort ); httpServer = httpServer.compress(currentConfiguration.getResponseCompressionThreshold()); } else { - CarapaceLogger.debug("Response compression disabled for listener {0}", hostPort); + LOG.debug("Response compression disabled for listener {}", hostPort); } // Initialization of event loop groups, native transport libraries and the native libraries for the security diff --git a/carapace-server/src/main/java/org/carapaceproxy/core/ProxyRequestsManager.java b/carapace-server/src/main/java/org/carapaceproxy/core/ProxyRequestsManager.java index a70100737..46c1bda2e 100644 --- a/carapace-server/src/main/java/org/carapaceproxy/core/ProxyRequestsManager.java +++ b/carapace-server/src/main/java/org/carapaceproxy/core/ProxyRequestsManager.java @@ -63,7 +63,6 @@ import org.carapaceproxy.server.config.NetworkListenerConfiguration; import org.carapaceproxy.server.mapper.CustomHeader; import org.carapaceproxy.server.mapper.MapResult; -import org.carapaceproxy.utils.CarapaceLogger; import org.carapaceproxy.utils.HttpUtils; import org.carapaceproxy.utils.PrometheusUtils; import org.reactivestreams.Publisher; @@ -366,12 +365,20 @@ public Publisher forward(ProxyRequest request, boolean cache) { var connectionToEndpoint = connectionsManager.apply(request); ConnectionPoolConfiguration connectionConfig = connectionToEndpoint.getKey(); ConnectionProvider connectionProvider = connectionToEndpoint.getValue(); - if (CarapaceLogger.isLoggingDebugEnabled()) { + if (LOGGER.isDebugEnabled()) { Map stats = parent.getConnectionPoolsStats().get(key); if (stats != null) { - CarapaceLogger.debug("Connection {0} stats: {1}", connectionConfig.getId(), stats.get(connectionConfig.getId())); + LOGGER.debug( + "Connection {} stats: {}", + connectionConfig.getId(), + stats.get(connectionConfig.getId()) + ); } - CarapaceLogger.debug("Max connections for {0}: {1}", connectionConfig.getId(), connectionProvider.maxConnectionsPerHost()); + LOGGER.debug( + "Max connections for {}: {}", + connectionConfig.getId(), + connectionProvider.maxConnectionsPerHost() + ); } final var protocol = HttpUtils.toHttpProtocol(request.getHttpProtocol(), request.isSecure()); @@ -398,22 +405,30 @@ public Publisher forward(ProxyRequest request, boolean cache) { : NioChannelOption.of(ExtendedSocketOptions.TCP_KEEPCOUNT), connectionConfig.getKeepaliveCount()) .httpResponseDecoder(option -> option.maxHeaderSize(parent.getCurrentConfiguration().getMaxHeaderSize())) .doOnRequest((req, conn) -> { - if (CarapaceLogger.isLoggingDebugEnabled()) { - CarapaceLogger.debug("Start sending request for " - + " Using client id " + key.toString() + "_" + connectionConfig.getId() - + " Uri " + req.resourceUrl() - + " Timestamp " + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd-HH-mm-ss.SSS")) - + " Backend " + endpointHost + ":" + endpointPort); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug( + "Start sending request for Using client id {}_{} Uri {} Timestamp {} Backend {}:{}", + key, + connectionConfig.getId(), + req.resourceUrl(), + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd-HH-mm-ss.SSS")), + endpointHost, + endpointPort + ); } endpointStats.getTotalRequests().incrementAndGet(); endpointStats.getLastActivity().set(System.currentTimeMillis()); }).doAfterRequest((req, conn) -> { - if (CarapaceLogger.isLoggingDebugEnabled()) { - CarapaceLogger.debug("Finished sending request for " - + " Using client id " + key.toString() + "_" + connectionConfig.getId() - + " Uri " + request.getUri() - + " Timestamp " + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd-HH-mm-ss.SSS")) - + " Backend " + endpointHost + ":" + endpointPort); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug( + "Finished sending request for Using client id {}_{} Uri {} Timestamp {} Backend {}:{}", + key, + connectionConfig.getId(), + request.getUri(), + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd-HH-mm-ss.SSS")), + endpointHost, + endpointPort + ); } }).doAfterResponseSuccess((resp, conn) -> { PENDING_REQUESTS_GAUGE.dec(); @@ -440,12 +455,16 @@ public Publisher forward(ProxyRequest request, boolean cache) { return out.send(request.getRequestData()); // client request body }) .response((resp, flux) -> { // endpoint response - if (CarapaceLogger.isLoggingDebugEnabled()) { - CarapaceLogger.debug("Receive response from backend for " + request.getRemoteAddress() - + " Using client id " + key.toString() + "_" + connectionConfig.getId() - + " uri" + request.getUri() - + " timestamp " + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd-HH-mm-ss.SSS")) - + " Backend: " + request.getAction().host); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug( + "Receive response from backend for {} Using client id {}_{} uri{} timestamp {} Backend: {}", + request.getRemoteAddress(), + key, + connectionConfig.getId(), + request.getUri(), + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd-HH-mm-ss.SSS")), + request.getAction().host + ); } request.setResponseStatus(resp.status()); @@ -479,12 +498,16 @@ public Publisher forward(ProxyRequest request, boolean cache) { cacheReceiver.receivedFromRemote(data, parent.getCachePoolAllocator()); } }).doOnComplete(() -> { - if (CarapaceLogger.isLoggingDebugEnabled()) { - CarapaceLogger.debug("Send all response to client " + request.getRemoteAddress() - + " Using client id " + key.toString() + "_" + connectionConfig.getId() - + " for uri " + request.getUri() - + " timestamp " + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd-HH-mm-ss.SSS")) - + " Backend: " + request.getAction().host); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug( + "Send all response to client {} Using client id {}_{} for uri {} timestamp {} Backend: {}", + request.getRemoteAddress(), + key, + connectionConfig.getId(), + request.getUri(), + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd-HH-mm-ss.SSS")), + request.getAction().host + ); } if (cacheable.get()) { parent.getCache().cacheContent(cacheReceiver); @@ -630,8 +653,12 @@ public void reloadConfiguration(RuntimeServerConfiguration newConfiguration, Col // max connections per endpoint limit setup newEndpoints.forEach(be -> { - CarapaceLogger.debug("Setup max connections per endpoint {0}:{1} = {2} for connectionpool {3}", - be.host(), be.port() + "", connectionPool.getMaxConnectionsPerEndpoint(), connectionPool.getId() + LOGGER.debug( + "Setup max connections per endpoint {}:{} = {} for connectionpool {}", + be.host(), + be.port(), + connectionPool.getMaxConnectionsPerEndpoint(), + connectionPool.getId() ); builder.forRemoteHost(InetSocketAddress.createUnresolved(be.host(), be.port()), spec -> { spec.maxConnections(connectionPool.getMaxConnectionsPerEndpoint()); @@ -677,7 +704,7 @@ public Map.Entry apply(ProxyReq .findFirst() .orElse(defaultConnectionPool); - CarapaceLogger.debug("Using connection {0} for domain {1}", selectedPool.getKey().getId(), hostName); + LOGGER.debug("Using connection {} for domain {}", selectedPool.getKey().getId(), hostName); return selectedPool; } diff --git a/carapace-server/src/main/java/org/carapaceproxy/core/RequestsLogger.java b/carapace-server/src/main/java/org/carapaceproxy/core/RequestsLogger.java index 58d7c3ecd..5ede9a05e 100644 --- a/carapace-server/src/main/java/org/carapaceproxy/core/RequestsLogger.java +++ b/carapace-server/src/main/java/org/carapaceproxy/core/RequestsLogger.java @@ -46,7 +46,6 @@ import java.util.concurrent.BlockingQueue; import java.util.concurrent.TimeUnit; import java.util.zip.GZIPOutputStream; -import org.carapaceproxy.server.cache.ContentsCache; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.stringtemplate.v4.NoIndentWriter; @@ -59,7 +58,7 @@ */ public class RequestsLogger implements Runnable, Closeable { - private static final Logger LOG = LoggerFactory.getLogger(ContentsCache.class); + private static final Logger LOG = LoggerFactory.getLogger(RequestsLogger.class); private final BlockingQueue queue; @@ -201,7 +200,7 @@ private void gzipFile(String source_filepath, String destination_zip_filepath, b LOG.info("{} was compressed successfully", source_filepath); } } catch (IOException ex) { - LOG.error("{} Compression failed: {}", source_filepath, ex); + LOG.error("{} Compression failed", source_filepath, ex); } } diff --git a/carapace-server/src/main/java/org/carapaceproxy/core/RuntimeServerConfiguration.java b/carapace-server/src/main/java/org/carapaceproxy/core/RuntimeServerConfiguration.java index 5729f548f..c68592ebb 100644 --- a/carapace-server/src/main/java/org/carapaceproxy/core/RuntimeServerConfiguration.java +++ b/carapace-server/src/main/java/org/carapaceproxy/core/RuntimeServerConfiguration.java @@ -55,7 +55,6 @@ import org.carapaceproxy.server.config.SSLCertificateConfiguration; import org.carapaceproxy.server.config.SSLCertificateConfiguration.CertificateMode; import org.carapaceproxy.server.mapper.StandardEndpointMapper; -import org.carapaceproxy.utils.CarapaceLogger; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -248,10 +247,6 @@ public void configure(ConfigurationStore properties) throws ConfigurationNotVali ocspStaplingManagerPeriod = properties.getInt("ocspstaplingmanager.period", 0); LOG.info("ocspstaplingmanager.period={}", ocspStaplingManagerPeriod); - boolean loggingDebugEnabled = properties.getBoolean("logging.debug.enabled", false); - CarapaceLogger.setLoggingDebugEnabled(loggingDebugEnabled); - LOG.info("logging.debug.enabled={}", loggingDebugEnabled); - clientsIdleTimeoutSeconds = properties.getInt("clients.idle.timeout", clientsIdleTimeoutSeconds); LOG.info("clients.idle.timeout={}", clientsIdleTimeoutSeconds); diff --git a/carapace-server/src/main/java/org/carapaceproxy/core/StaticContentsManager.java b/carapace-server/src/main/java/org/carapaceproxy/core/StaticContentsManager.java index 53bf47c1a..0c4698e1d 100644 --- a/carapace-server/src/main/java/org/carapaceproxy/core/StaticContentsManager.java +++ b/carapace-server/src/main/java/org/carapaceproxy/core/StaticContentsManager.java @@ -111,7 +111,7 @@ private static ByteBuf loadResource(String resource) { throw new IOException("cannot load resource " + resource + ", path must start with " + FILE_RESOURCE + " or " + CLASSPATH_RESOURCE); } } catch (IOException | NullPointerException err) { - LOG.error("Cannot load resource {}: {}", resource, err); + LOG.error("Cannot load resource {}", resource, err); return null; } } diff --git a/carapace-server/src/main/java/org/carapaceproxy/core/TrustStoreManager.java b/carapace-server/src/main/java/org/carapaceproxy/core/TrustStoreManager.java index 35fa83983..9bf508abc 100644 --- a/carapace-server/src/main/java/org/carapaceproxy/core/TrustStoreManager.java +++ b/carapace-server/src/main/java/org/carapaceproxy/core/TrustStoreManager.java @@ -1,10 +1,6 @@ package org.carapaceproxy.core; -import lombok.Getter; -import org.carapaceproxy.utils.CertificatesUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import javax.net.ssl.TrustManagerFactory; +import static org.carapaceproxy.utils.CertificatesUtils.loadKeyStoreFromFile; import java.io.File; import java.io.IOException; import java.security.KeyStore; @@ -14,8 +10,11 @@ import java.security.cert.X509Certificate; import java.util.HashMap; import java.util.Map; - -import static org.carapaceproxy.utils.CertificatesUtils.loadKeyStoreFromFile; +import javax.net.ssl.TrustManagerFactory; +import lombok.Getter; +import org.carapaceproxy.utils.CertificatesUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class TrustStoreManager { @@ -39,7 +38,7 @@ private void loadTrustStore() { String trustStoreFile = currentConfiguration.getSslTrustStoreFile(); String trustStorePassword = currentConfiguration.getSslTrustStorePassword(); - if(trustStoreFile == null) { + if (trustStoreFile == null) { return; } diff --git a/carapace-server/src/main/java/org/carapaceproxy/launcher/ZooKeeperMainWrapper.java b/carapace-server/src/main/java/org/carapaceproxy/launcher/ZooKeeperMainWrapper.java index 08b8a3df9..54ba622a0 100644 --- a/carapace-server/src/main/java/org/carapaceproxy/launcher/ZooKeeperMainWrapper.java +++ b/carapace-server/src/main/java/org/carapaceproxy/launcher/ZooKeeperMainWrapper.java @@ -69,8 +69,7 @@ public static void main(String... args) { if (!arg.startsWith("-")) { File configFile = new File(args[i]).getAbsoluteFile(); LOG.error("Reading configuration from {}", configFile); - try (InputStreamReader reader - = new InputStreamReader(new FileInputStream(configFile), StandardCharsets.UTF_8)) { + try (InputStreamReader reader = new InputStreamReader(new FileInputStream(configFile), StandardCharsets.UTF_8)) { configuration.load(reader); } configFileFromParameter = true; diff --git a/carapace-server/src/main/java/org/carapaceproxy/server/cache/CacheByteBufMemoryUsageMetric.java b/carapace-server/src/main/java/org/carapaceproxy/server/cache/CacheByteBufMemoryUsageMetric.java index af1260638..23a4b1d97 100644 --- a/carapace-server/src/main/java/org/carapaceproxy/server/cache/CacheByteBufMemoryUsageMetric.java +++ b/carapace-server/src/main/java/org/carapaceproxy/server/cache/CacheByteBufMemoryUsageMetric.java @@ -3,14 +3,14 @@ import io.netty.buffer.PooledByteBufAllocator; import io.netty.buffer.UnpooledByteBufAllocator; import io.prometheus.client.Gauge; -import org.carapaceproxy.core.HttpProxyServer; -import org.carapaceproxy.utils.PrometheusUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; +import org.carapaceproxy.core.HttpProxyServer; +import org.carapaceproxy.utils.PrometheusUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class CacheByteBufMemoryUsageMetric implements Runnable { diff --git a/carapace-server/src/main/java/org/carapaceproxy/server/cache/CaffeineCacheImpl.java b/carapace-server/src/main/java/org/carapaceproxy/server/cache/CaffeineCacheImpl.java index 4767eb4f6..b4ff8c551 100644 --- a/carapace-server/src/main/java/org/carapaceproxy/server/cache/CaffeineCacheImpl.java +++ b/carapace-server/src/main/java/org/carapaceproxy/server/cache/CaffeineCacheImpl.java @@ -25,9 +25,9 @@ import com.github.benmanes.caffeine.cache.RemovalCause; import com.github.benmanes.caffeine.cache.RemovalListener; import java.util.concurrent.atomic.AtomicLong; +import org.carapaceproxy.server.cache.ContentsCache.CachedContent; import org.carapaceproxy.server.cache.ContentsCache.ContentKey; import org.slf4j.Logger; -import org.carapaceproxy.server.cache.ContentsCache.CachedContent; /** * diff --git a/carapace-server/src/main/java/org/carapaceproxy/server/certificates/DynamicCertificatesManager.java b/carapace-server/src/main/java/org/carapaceproxy/server/certificates/DynamicCertificatesManager.java index a676379d7..ee0c938ac 100644 --- a/carapace-server/src/main/java/org/carapaceproxy/server/certificates/DynamicCertificatesManager.java +++ b/carapace-server/src/main/java/org/carapaceproxy/server/certificates/DynamicCertificatesManager.java @@ -391,7 +391,7 @@ private void startCertificateProcessing(final String domain, final CertificateDa } } } catch (AcmeException | IOException ex) { - LOG.error("Domain checking failed for {}: {}", name, ex); + LOG.error("Domain checking failed for {}", name, ex); unreachableNames.put(name, ex.getMessage()); } } diff --git a/carapace-server/src/main/java/org/carapaceproxy/server/certificates/Route53Client.java b/carapace-server/src/main/java/org/carapaceproxy/server/certificates/Route53Client.java index deeb77c26..a6b2b7870 100644 --- a/carapace-server/src/main/java/org/carapaceproxy/server/certificates/Route53Client.java +++ b/carapace-server/src/main/java/org/carapaceproxy/server/certificates/Route53Client.java @@ -106,7 +106,7 @@ private boolean performActionOnDnsChallengeForDomain(String domain, String diges ListHostedZonesByNameResponse res = client.listHostedZonesByName( ListHostedZonesByNameRequest.builder().dnsName(dnsName).build() ).exceptionally(ext -> { - LOG.error("ERROR performing {} action for dns name {}. Reason: {}", action, dnsName, ext); + LOG.error("ERROR performing {} action for dns name {}.", action, dnsName, ext); return null; }).get(); @@ -152,7 +152,7 @@ private boolean performActionOnDnsChallengeForDomain(String domain, String diges } Route53Response actionResult; actionResult = future.exceptionally(ext -> { - LOG.error("ERROR performing {} action for dns name {}. Reason: {}", action, dnsName, ext); + LOG.error("ERROR performing {} action for dns name {}.", action, dnsName, ext); return null; }).get(); if (actionResult != null && actionResult.sdkHttpResponse().isSuccessful()) { @@ -163,7 +163,7 @@ private boolean performActionOnDnsChallengeForDomain(String domain, String diges return true; } } catch (InterruptedException | ExecutionException ex) { - LOG.error("ERROR performing {} action for dns name {}. Reason: {}", action, dnsName, ex); + LOG.error("ERROR performing {} action for dns name {}.", action, dnsName, ex); } return false; diff --git a/carapace-server/src/main/java/org/carapaceproxy/server/certificates/ocsp/OcspUtils.java b/carapace-server/src/main/java/org/carapaceproxy/server/certificates/ocsp/OcspUtils.java index ba2514b0f..ec6e42298 100644 --- a/carapace-server/src/main/java/org/carapaceproxy/server/certificates/ocsp/OcspUtils.java +++ b/carapace-server/src/main/java/org/carapaceproxy/server/certificates/ocsp/OcspUtils.java @@ -19,6 +19,8 @@ */ package org.carapaceproxy.server.certificates.ocsp; +import io.netty.util.CharsetUtil; +import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -31,21 +33,19 @@ import java.util.concurrent.TimeUnit; import javax.net.ssl.HttpsURLConnection; import javax.security.auth.x500.X500Principal; -import org.bouncycastle.asn1.ASN1Primitive; -import org.bouncycastle.asn1.x509.Extension; -import org.bouncycastle.cert.ocsp.OCSPReq; -import org.bouncycastle.cert.ocsp.OCSPResp; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import io.netty.util.CharsetUtil; -import java.io.ByteArrayInputStream; import org.bouncycastle.asn1.ASN1InputStream; import org.bouncycastle.asn1.ASN1OctetString; +import org.bouncycastle.asn1.ASN1Primitive; import org.bouncycastle.asn1.ASN1TaggedObject; import org.bouncycastle.asn1.x509.AccessDescription; import org.bouncycastle.asn1.x509.AuthorityInformationAccess; +import org.bouncycastle.asn1.x509.Extension; import org.bouncycastle.asn1.x509.GeneralName; import org.bouncycastle.asn1.x509.X509ObjectIdentifiers; +import org.bouncycastle.cert.ocsp.OCSPReq; +import org.bouncycastle.cert.ocsp.OCSPResp; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public final class OcspUtils { @@ -57,7 +57,7 @@ public final class OcspUtils { private static final String OCSP_REQUEST_TYPE = "application/ocsp-request"; private static final String OCSP_RESPONSE_TYPE = "application/ocsp-response"; - private static final Logger LOG = LoggerFactory.getLogger(OcspStaplingManager.class); + private static final Logger LOG = LoggerFactory.getLogger(OcspUtils.class); private OcspUtils() { } diff --git a/carapace-server/src/main/java/org/carapaceproxy/user/FileUserRealm.java b/carapace-server/src/main/java/org/carapaceproxy/user/FileUserRealm.java index 1690ad694..aa64dbe49 100644 --- a/carapace-server/src/main/java/org/carapaceproxy/user/FileUserRealm.java +++ b/carapace-server/src/main/java/org/carapaceproxy/user/FileUserRealm.java @@ -19,6 +19,7 @@ */ package org.carapaceproxy.user; +import static org.carapaceproxy.utils.StringUtils.trimToNull; import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -35,8 +36,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import static org.carapaceproxy.utils.StringUtils.trimToNull; - /** * User realm that takes the initial configuration of the authorized users from * a file specified in the server.properties. diff --git a/carapace-server/src/main/java/org/carapaceproxy/utils/CarapaceLogger.java b/carapace-server/src/main/java/org/carapaceproxy/utils/CarapaceLogger.java deleted file mode 100644 index a38c3d660..000000000 --- a/carapace-server/src/main/java/org/carapaceproxy/utils/CarapaceLogger.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - Licensed to Diennea S.r.l. under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. Diennea S.r.l. licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. - - */ -package org.carapaceproxy.utils; - -import org.slf4j.LoggerFactory; -import org.slf4j.event.Level; - -/** - * @author paolo.venturi - */ -public final class CarapaceLogger { - - private static final org.slf4j.Logger LOG = LoggerFactory.getLogger(CarapaceLogger.class); - - private static boolean loggingDebugEnabled = false; - - private CarapaceLogger() { - } - - public static boolean isLoggingDebugEnabled() { - return loggingDebugEnabled; - } - - public static void setLoggingDebugEnabled(boolean loggingDebugEnabled) { - CarapaceLogger.loggingDebugEnabled = loggingDebugEnabled; - } - - /** - * This method assumes that {@link Level#DEBUG debug log level} is disabled. - * If {@link #setLoggingDebugEnabled(boolean) Carapace log level was enabled}, - * forwards the log event to the {@link Level#INFO info log level} instead of using the debug level. - * - * @param s the format string - * @param o a list of arguments - */ - public static void debug(String s, Object... o) { - (loggingDebugEnabled ? LOG.atInfo() : LOG.atDebug()).log(s, o); - } -} diff --git a/carapace-server/src/main/resources/logback.xml b/carapace-server/src/main/resources/logback.xml index ee25b1c08..0baee9328 100644 --- a/carapace-server/src/main/resources/logback.xml +++ b/carapace-server/src/main/resources/logback.xml @@ -2,7 +2,9 @@ + xsi:schemaLocation="http://ch.qos.logback/xml/ns/logback https://raw.githubusercontent.com/enricopulatzo/logback-XSD/master/src/main/xsd/logback.xsd" + scan="true" + scanPeriod="1 minute"> diff --git a/carapace-server/src/test/java/org/carapaceproxy/RawClientTest.java b/carapace-server/src/test/java/org/carapaceproxy/RawClientTest.java index 296c1f6cf..6058f1f6f 100644 --- a/carapace-server/src/test/java/org/carapaceproxy/RawClientTest.java +++ b/carapace-server/src/test/java/org/carapaceproxy/RawClientTest.java @@ -93,7 +93,6 @@ import org.carapaceproxy.server.config.ConnectionPoolConfiguration; import org.carapaceproxy.server.config.NetworkListenerConfiguration; import org.carapaceproxy.server.config.SSLCertificateConfiguration; -import org.carapaceproxy.utils.CarapaceLogger; import org.carapaceproxy.utils.RawHttpClient; import org.carapaceproxy.utils.RawHttpClient.HttpResponse; import org.carapaceproxy.utils.RawHttpServer; @@ -323,8 +322,6 @@ public void testServerRequestContinue() throws Exception { ExecutorService ex = Executors.newFixedThreadPool(2); List futures = new ArrayList<>(); - CarapaceLogger.setLoggingDebugEnabled(true); - try (HttpProxyServer proxy = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder())) { ConnectionPoolConfiguration defaultConnectionPool = proxy.getCurrentConfiguration().getDefaultConnectionPool(); defaultConnectionPool.setMaxConnectionsPerEndpoint(1); @@ -539,8 +536,6 @@ public void testMultiClientTimeout() throws Exception { ExecutorService ex = Executors.newFixedThreadPool(2); List futures = new ArrayList<>(); - CarapaceLogger.setLoggingDebugEnabled(true); - try (HttpProxyServer proxy = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder())) { ConnectionPoolConfiguration defaultConnectionPool = proxy.getCurrentConfiguration().getDefaultConnectionPool(); defaultConnectionPool.setMaxConnectionsPerEndpoint(1); @@ -619,7 +614,6 @@ public void testMultiClientTimeout() throws Exception { @Test public void testMaxConnectionsAndBorrowTimeout() throws Exception { - CarapaceLogger.setLoggingDebugEnabled(true); ExecutorService ex = Executors.newFixedThreadPool(2); List futures = new ArrayList<>(); AtomicBoolean responseEnabled = new AtomicBoolean(); diff --git a/carapace-server/src/test/java/org/carapaceproxy/RealBackendsTest.java b/carapace-server/src/test/java/org/carapaceproxy/RealBackendsTest.java index 179fb2dc6..f1cce0eaa 100644 --- a/carapace-server/src/test/java/org/carapaceproxy/RealBackendsTest.java +++ b/carapace-server/src/test/java/org/carapaceproxy/RealBackendsTest.java @@ -31,7 +31,6 @@ import java.util.concurrent.atomic.AtomicInteger; import org.carapaceproxy.core.HttpProxyServer; import org.carapaceproxy.core.RuntimeServerConfiguration; -import org.carapaceproxy.utils.CarapaceLogger; import org.carapaceproxy.utils.RawHttpClient; import org.carapaceproxy.utils.TestEndpointMapper; import org.junit.Ignore; @@ -83,8 +82,6 @@ private static RawHttpClient.HttpResponse doPost(RawHttpClient client, String ho @Test @Ignore public void testRequestsRealBackend() throws Exception { - CarapaceLogger.setLoggingDebugEnabled(true); - String host = ""; int threads = 15; final int requestsPerClient = 1000; diff --git a/carapace-server/src/test/java/org/carapaceproxy/backends/ChunkedEncodingResponseTest.java b/carapace-server/src/test/java/org/carapaceproxy/backends/ChunkedEncodingResponseTest.java index defbeec0d..727bfbce9 100644 --- a/carapace-server/src/test/java/org/carapaceproxy/backends/ChunkedEncodingResponseTest.java +++ b/carapace-server/src/test/java/org/carapaceproxy/backends/ChunkedEncodingResponseTest.java @@ -38,7 +38,6 @@ import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.carapaceproxy.core.HttpProxyServer; -import org.carapaceproxy.utils.CarapaceLogger; import org.carapaceproxy.utils.RawHttpClient; import org.carapaceproxy.utils.TestEndpointMapper; import org.carapaceproxy.utils.TestUtils; @@ -70,7 +69,6 @@ public void testSimpleChunkedResponseNoCache() throws Exception { ); TestEndpointMapper mapper = new TestEndpointMapper("localhost", wireMockRule.port()); - CarapaceLogger.setLoggingDebugEnabled(true); try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder())) { server.start(); int port = server.getLocalPort(); diff --git a/carapace-server/src/test/java/org/carapaceproxy/backends/RestartEndpointTest.java b/carapace-server/src/test/java/org/carapaceproxy/backends/RestartEndpointTest.java index e23a53de5..5fa13ad4f 100644 --- a/carapace-server/src/test/java/org/carapaceproxy/backends/RestartEndpointTest.java +++ b/carapace-server/src/test/java/org/carapaceproxy/backends/RestartEndpointTest.java @@ -35,7 +35,6 @@ import java.nio.charset.StandardCharsets; import org.apache.commons.io.IOUtils; import org.carapaceproxy.core.HttpProxyServer; -import org.carapaceproxy.utils.CarapaceLogger; import org.carapaceproxy.utils.RawHttpClient; import org.carapaceproxy.utils.TestEndpointMapper; import org.junit.Rule; @@ -150,7 +149,6 @@ public void testClientsSendsRequestBackendRestart() throws Exception { )); TestEndpointMapper mapper = new TestEndpointMapper("localhost", wireMockRule.port()); - CarapaceLogger.setLoggingDebugEnabled(true); try (HttpProxyServer server = HttpProxyServer.buildForTests("localhost", 0, mapper, tmpDir.newFolder());) { server.start(); int port = server.getLocalPort();