From 277ae79226d4f3cb50edb32baf554cec95f23ba3 Mon Sep 17 00:00:00 2001 From: Alexander Senn Date: Thu, 17 Dec 2020 10:13:25 -0500 Subject: [PATCH 1/5] Change logger.info and logger.warn statements, fix basicAuthManagerTest --- .../redhat/rhjmc/containerjfr/ContainerJfr.java | 5 +---- .../rhjmc/containerjfr/net/BasicAuthManager.java | 6 +++--- .../containerjfr/net/BasicAuthManagerTest.java | 15 ++++++++++----- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/redhat/rhjmc/containerjfr/ContainerJfr.java b/src/main/java/com/redhat/rhjmc/containerjfr/ContainerJfr.java index 42f0f16098..15daf612d1 100644 --- a/src/main/java/com/redhat/rhjmc/containerjfr/ContainerJfr.java +++ b/src/main/java/com/redhat/rhjmc/containerjfr/ContainerJfr.java @@ -62,10 +62,7 @@ public static void main(String[] args) throws Exception { logger.trace(String.format("env: %s", environment.getEnv().toString())); - logger.info( - String.format( - "%s started.", - System.getProperty("java.rmi.server.hostname", "container-jfr"))); + logger.info("{} started.", System.getProperty("java.rmi.server.hostname", "container-jfr")); Client client = DaggerContainerJfr_Client.builder().build(); diff --git a/src/main/java/com/redhat/rhjmc/containerjfr/net/BasicAuthManager.java b/src/main/java/com/redhat/rhjmc/containerjfr/net/BasicAuthManager.java index 1c576db054..9aa2b69570 100644 --- a/src/main/java/com/redhat/rhjmc/containerjfr/net/BasicAuthManager.java +++ b/src/main/java/com/redhat/rhjmc/containerjfr/net/BasicAuthManager.java @@ -146,15 +146,15 @@ public Future validateWebSocketSubProtocol(Supplier subProtocol synchronized void loadConfig() { Path properties = fs.pathOf(System.getProperty("user.home"), USER_PROPERTIES_FILENAME); if (!fs.exists(properties)) { - logger.warn(String.format("User properties file \"%s\" does not exist", properties)); + logger.warn("User properties file \"{}\" does not exist", properties); return; } if (!fs.isRegularFile(properties)) { - logger.warn(String.format("User properties path \"%s\" is not a file", properties)); + logger.warn("User properties path \"{}\" is not a file", properties); return; } if (!fs.isReadable(properties)) { - logger.warn(String.format("User properties file \"%s\" is not readable", properties)); + logger.warn("User properties file \"{}\" is not readable", properties); return; } try (Reader br = fs.readFile(properties)) { diff --git a/src/test/java/com/redhat/rhjmc/containerjfr/net/BasicAuthManagerTest.java b/src/test/java/com/redhat/rhjmc/containerjfr/net/BasicAuthManagerTest.java index 9de0b5d889..2a68879883 100644 --- a/src/test/java/com/redhat/rhjmc/containerjfr/net/BasicAuthManagerTest.java +++ b/src/test/java/com/redhat/rhjmc/containerjfr/net/BasicAuthManagerTest.java @@ -83,7 +83,8 @@ void shouldWarnWhenPropertiesNotFound() throws Exception { mgr.loadConfig(); ArgumentCaptor messageCaptor = ArgumentCaptor.forClass(String.class); - Mockito.verify(logger).warn(messageCaptor.capture()); + ArgumentCaptor objectCaptor = ArgumentCaptor.forClass(Object.class); + Mockito.verify(logger).warn(messageCaptor.capture(), objectCaptor.capture()); MatcherAssert.assertThat( messageCaptor.getValue(), Matchers.stringContainsInOrder("User properties file", "does not exist")); @@ -103,7 +104,8 @@ void shouldWarnWhenPropertiesNotFile() throws Exception { mgr.loadConfig(); ArgumentCaptor messageCaptor = ArgumentCaptor.forClass(String.class); - Mockito.verify(logger).warn(messageCaptor.capture()); + ArgumentCaptor objectCaptor = ArgumentCaptor.forClass(Object.class); + Mockito.verify(logger).warn(messageCaptor.capture(), objectCaptor.capture()); MatcherAssert.assertThat( messageCaptor.getValue(), Matchers.stringContainsInOrder("User properties path", "is not a file")); @@ -124,7 +126,8 @@ void shouldWarnWhenPropertiesNotReadable() throws Exception { mgr.loadConfig(); ArgumentCaptor messageCaptor = ArgumentCaptor.forClass(String.class); - Mockito.verify(logger).warn(messageCaptor.capture()); + ArgumentCaptor objectCaptor = ArgumentCaptor.forClass(Object.class); + Mockito.verify(logger).warn(messageCaptor.capture(), objectCaptor.capture()); MatcherAssert.assertThat( messageCaptor.getValue(), Matchers.stringContainsInOrder("User properties file", "is not readable")); @@ -156,7 +159,8 @@ class TokenValidationTest { void shouldFailAuthenticationWhenCredentialsMalformed() throws Exception { Assertions.assertFalse(mgr.validateToken(() -> "user").get()); ArgumentCaptor messageCaptor = ArgumentCaptor.forClass(String.class); - Mockito.verify(logger).warn(messageCaptor.capture()); + ArgumentCaptor objectCaptor = ArgumentCaptor.forClass(Object.class); + Mockito.verify(logger).warn(messageCaptor.capture(), objectCaptor.capture()); MatcherAssert.assertThat( messageCaptor.getValue(), Matchers.stringContainsInOrder("User properties file", "does not exist")); @@ -166,7 +170,8 @@ void shouldFailAuthenticationWhenCredentialsMalformed() throws Exception { void shouldFailAuthenticationWhenNoMatchFound() throws Exception { Assertions.assertFalse(mgr.validateToken(() -> "user:pass").get()); ArgumentCaptor messageCaptor = ArgumentCaptor.forClass(String.class); - Mockito.verify(logger).warn(messageCaptor.capture()); + ArgumentCaptor objectCaptor = ArgumentCaptor.forClass(Object.class); + Mockito.verify(logger).warn(messageCaptor.capture(), objectCaptor.capture()); MatcherAssert.assertThat( messageCaptor.getValue(), Matchers.stringContainsInOrder("User properties file", "does not exist")); From e473464e84aacc22ca7a39722476bca5762b0e58 Mon Sep 17 00:00:00 2001 From: Alexander Senn Date: Thu, 17 Dec 2020 11:00:52 -0500 Subject: [PATCH 2/5] remove string formatting from most logger.info --- .../redhat/rhjmc/containerjfr/MainModule.java | 2 +- .../containerjfr/messaging/MessagingModule.java | 10 ++-------- .../containerjfr/messaging/MessagingServer.java | 16 ++++++---------- .../rhjmc/containerjfr/messaging/WsClient.java | 2 +- .../rhjmc/containerjfr/net/SslConfiguration.java | 10 +++------- .../web/http/api/v1/RecordingsPostHandler.java | 3 +-- .../web/http/api/v1/TemplatesPostHandler.java | 4 +--- .../containerjfr/platform/PlatformModule.java | 10 +++------- 8 files changed, 18 insertions(+), 39 deletions(-) diff --git a/src/main/java/com/redhat/rhjmc/containerjfr/MainModule.java b/src/main/java/com/redhat/rhjmc/containerjfr/MainModule.java index 39ea93e000..b36e6e2493 100644 --- a/src/main/java/com/redhat/rhjmc/containerjfr/MainModule.java +++ b/src/main/java/com/redhat/rhjmc/containerjfr/MainModule.java @@ -124,7 +124,7 @@ public static Gson provideGson(Logger logger) { @Named(RECORDINGS_PATH) static Path provideSavedRecordingsPath(Logger logger, Environment env) { String ARCHIVE_PATH = env.getEnv("CONTAINER_JFR_ARCHIVE_PATH", "/flightrecordings"); - logger.info(String.format("Local save path for flight recordings set as %s", ARCHIVE_PATH)); + logger.info("Local save path for flight recordings set as {}", ARCHIVE_PATH); return Paths.get(ARCHIVE_PATH); } } diff --git a/src/main/java/com/redhat/rhjmc/containerjfr/messaging/MessagingModule.java b/src/main/java/com/redhat/rhjmc/containerjfr/messaging/MessagingModule.java index 1b9b1eb689..d3dcc8c170 100644 --- a/src/main/java/com/redhat/rhjmc/containerjfr/messaging/MessagingModule.java +++ b/src/main/java/com/redhat/rhjmc/containerjfr/messaging/MessagingModule.java @@ -112,17 +112,11 @@ static int provideWebSocketMaxConnections(Environment env, Logger logger) { MAX_CONNECTIONS_ENV_VAR, String.valueOf(DEFAULT_MAX_CONNECTIONS))); if (maxConn > MAX_CONNECTIONS) { - logger.info( - String.format( - "Requested maximum WebSocket connections %d is too large.", - maxConn)); + logger.info("Requested maximum WebSocket connections {} is too large.", maxConn); return MAX_CONNECTIONS; } if (maxConn < MIN_CONNECTIONS) { - logger.info( - String.format( - "Requested maximum WebSocket connections %d is too small.", - maxConn)); + logger.info("Requested maximum WebSocket connections {} is too small.", maxConn); return MIN_CONNECTIONS; } return maxConn; diff --git a/src/main/java/com/redhat/rhjmc/containerjfr/messaging/MessagingServer.java b/src/main/java/com/redhat/rhjmc/containerjfr/messaging/MessagingServer.java index e65668b267..9d1ac01c7f 100644 --- a/src/main/java/com/redhat/rhjmc/containerjfr/messaging/MessagingServer.java +++ b/src/main/java/com/redhat/rhjmc/containerjfr/messaging/MessagingServer.java @@ -95,7 +95,7 @@ public class MessagingServer implements AutoCloseable { } public void start() throws SocketException, UnknownHostException { - logger.info(String.format("Max concurrent WebSocket connections: %d", maxConnections)); + logger.info("Max concurrent WebSocket connections: {}", maxConnections); server.websocketHandler( (sws) -> { @@ -107,22 +107,18 @@ public void start() throws SocketException, UnknownHostException { synchronized (connections) { if (connections.size() >= maxConnections) { logger.info( - String.format( - "Dropping remote client %s due to too many concurrent connections", - remoteAddress)); + "Dropping remote client {} due to too many concurrent connections", + remoteAddress); sws.reject(); sendClientActivityNotification(remoteAddress, "dropped"); return; } - logger.info(String.format("Connected remote client %s", remoteAddress)); + logger.info("Connected remote client {}", remoteAddress); WsClient crw = new WsClient(this.logger, sws); sws.closeHandler( (unused) -> { - logger.info( - String.format( - "Disconnected remote client %s", - remoteAddress)); + logger.info("Disconnected remote client {}", remoteAddress); sendClientActivityNotification(remoteAddress, "disconnected"); removeConnection(crw); }); @@ -173,7 +169,7 @@ public String readMessage() { public void writeMessage(WsMessage message) { String json = gson.toJson(message); - logger.info(String.format("Outgoing WS message: %s", json)); + logger.info("Outgoing WS message: {}", json); synchronized (connections) { connections.keySet().forEach(c -> c.writeMessage(json)); } diff --git a/src/main/java/com/redhat/rhjmc/containerjfr/messaging/WsClient.java b/src/main/java/com/redhat/rhjmc/containerjfr/messaging/WsClient.java index b31dc927d2..db617401da 100644 --- a/src/main/java/com/redhat/rhjmc/containerjfr/messaging/WsClient.java +++ b/src/main/java/com/redhat/rhjmc/containerjfr/messaging/WsClient.java @@ -65,7 +65,7 @@ class WsClient implements AutoCloseable, Handler { @Override public void handle(String msg) { - logger.info(String.format("(%s): CMD %s", this.sws.remoteAddress().toString(), msg)); + logger.info("({}): CMD {}", this.sws.remoteAddress().toString(), msg); inQ.add(msg); } diff --git a/src/main/java/com/redhat/rhjmc/containerjfr/net/SslConfiguration.java b/src/main/java/com/redhat/rhjmc/containerjfr/net/SslConfiguration.java index feb8947ee4..f4904fd91e 100644 --- a/src/main/java/com/redhat/rhjmc/containerjfr/net/SslConfiguration.java +++ b/src/main/java/com/redhat/rhjmc/containerjfr/net/SslConfiguration.java @@ -76,10 +76,7 @@ class SslConfiguration { Path path = obtainKeyStorePathIfSpecified(); if (path != null) { strategy = new KeyStoreStrategy(path, env.getEnv(KEYSTORE_PASS_ENV, "")); - logger.info( - String.format( - "Selected SSL KeyStore strategy with keystore %s", - path.toString())); + logger.info("Selected SSL KeyStore strategy with keystore {}", path.toString()); return; } } @@ -91,9 +88,8 @@ class SslConfiguration { Path cert = pair.getRight(); strategy = new KeyCertStrategy(key, cert); logger.info( - String.format( - "Selected SSL KeyCert strategy with key %s and cert %s", - key.toString(), cert.toString())); + "Selected SSL KeyCert strategy with key {} and cert {}", + key.toString(), cert.toString()); return; } } diff --git a/src/main/java/com/redhat/rhjmc/containerjfr/net/web/http/api/v1/RecordingsPostHandler.java b/src/main/java/com/redhat/rhjmc/containerjfr/net/web/http/api/v1/RecordingsPostHandler.java index 10cc552699..7500f51129 100644 --- a/src/main/java/com/redhat/rhjmc/containerjfr/net/web/http/api/v1/RecordingsPostHandler.java +++ b/src/main/java/com/redhat/rhjmc/containerjfr/net/web/http/api/v1/RecordingsPostHandler.java @@ -195,8 +195,7 @@ public void handleAuthenticated(RoutingContext ctx) throws Exception { HttpMimeType.JSON.mime()) .end(gson.toJson(Map.of("name", res2.result()))); - logger.info( - String.format("Recording saved as %s", res2.result())); + logger.info("Recording saved as {}", res2.result()); })); } diff --git a/src/main/java/com/redhat/rhjmc/containerjfr/net/web/http/api/v1/TemplatesPostHandler.java b/src/main/java/com/redhat/rhjmc/containerjfr/net/web/http/api/v1/TemplatesPostHandler.java index f98d0f580c..f01fde31d5 100644 --- a/src/main/java/com/redhat/rhjmc/containerjfr/net/web/http/api/v1/TemplatesPostHandler.java +++ b/src/main/java/com/redhat/rhjmc/containerjfr/net/web/http/api/v1/TemplatesPostHandler.java @@ -102,9 +102,7 @@ public void handleAuthenticated(RoutingContext ctx) throws Exception { Path path = fs.pathOf(u.uploadedFileName()); try (InputStream is = fs.newInputStream(path)) { if (!"template".equals(u.name())) { - logger.info( - String.format( - "Received unexpected file upload named %s", u.name())); + logger.info("Received unexpected file upload named {}", u.name()); continue; } templateService.addTemplate(is); diff --git a/src/main/java/com/redhat/rhjmc/containerjfr/platform/PlatformModule.java b/src/main/java/com/redhat/rhjmc/containerjfr/platform/PlatformModule.java index 105a173ff5..75528392ab 100644 --- a/src/main/java/com/redhat/rhjmc/containerjfr/platform/PlatformModule.java +++ b/src/main/java/com/redhat/rhjmc/containerjfr/platform/PlatformModule.java @@ -84,12 +84,10 @@ static AuthManager provideAuthManager( final String authManagerClass; if (env.hasEnv(AUTH_MANAGER_ENV_VAR)) { authManagerClass = env.getEnv(AUTH_MANAGER_ENV_VAR); - logger.info(String.format("Selecting configured AuthManager \"%s\"", authManagerClass)); + logger.info("Selecting configured AuthManager \"{}\"", authManagerClass); } else { authManagerClass = platformStrategy.getAuthManager().getClass().getCanonicalName(); - logger.info( - String.format( - "Selecting platform default AuthManager \"%s\"", authManagerClass)); + logger.info("Selecting platform default AuthManager \"{}\"", authManagerClass); } return authManagers.stream() .filter(mgr -> Objects.equals(mgr.getClass().getCanonicalName(), authManagerClass)) @@ -109,9 +107,7 @@ static PlatformDetectionStrategy providePlatformStrategy( PlatformDetectionStrategy strat = null; if (env.hasEnv(PLATFORM_STRATEGY_ENV_VAR)) { String platform = env.getEnv(PLATFORM_STRATEGY_ENV_VAR); - logger.info( - String.format( - "Selecting configured PlatformDetectionStrategy \"%s\"", platform)); + logger.info("Selecting configured PlatformDetectionStrategy \"{}\"", platform); for (PlatformDetectionStrategy s : strategies) { if (Objects.equals(platform, s.getClass().getCanonicalName())) { strat = s; From 7ed65f8fdb5904a546bb65d8d0cd8be644bd7734 Mon Sep 17 00:00:00 2001 From: Alexander Senn Date: Thu, 17 Dec 2020 14:06:13 -0500 Subject: [PATCH 3/5] remove string.format from logger.trace statements --- .../com/redhat/rhjmc/containerjfr/ContainerJfr.java | 2 +- .../rhjmc/containerjfr/net/SslConfiguration.java | 3 ++- .../containerjfr/net/TargetConnectionManager.java | 8 ++------ .../net/reports/ActiveRecordingReportCache.java | 10 ++++------ .../net/reports/ArchivedRecordingReportCache.java | 7 ++----- .../redhat/rhjmc/containerjfr/net/web/WebServer.java | 4 +--- 6 files changed, 12 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/redhat/rhjmc/containerjfr/ContainerJfr.java b/src/main/java/com/redhat/rhjmc/containerjfr/ContainerJfr.java index 15daf612d1..4519c1fbe0 100644 --- a/src/main/java/com/redhat/rhjmc/containerjfr/ContainerJfr.java +++ b/src/main/java/com/redhat/rhjmc/containerjfr/ContainerJfr.java @@ -60,7 +60,7 @@ public static void main(String[] args) throws Exception { final Logger logger = Logger.INSTANCE; final Environment environment = new Environment(); - logger.trace(String.format("env: %s", environment.getEnv().toString())); + logger.trace("env: {}", environment.getEnv().toString()); logger.info("{} started.", System.getProperty("java.rmi.server.hostname", "container-jfr")); diff --git a/src/main/java/com/redhat/rhjmc/containerjfr/net/SslConfiguration.java b/src/main/java/com/redhat/rhjmc/containerjfr/net/SslConfiguration.java index f4904fd91e..a782ec6655 100644 --- a/src/main/java/com/redhat/rhjmc/containerjfr/net/SslConfiguration.java +++ b/src/main/java/com/redhat/rhjmc/containerjfr/net/SslConfiguration.java @@ -89,7 +89,8 @@ class SslConfiguration { strategy = new KeyCertStrategy(key, cert); logger.info( "Selected SSL KeyCert strategy with key {} and cert {}", - key.toString(), cert.toString()); + key.toString(), + cert.toString()); return; } } diff --git a/src/main/java/com/redhat/rhjmc/containerjfr/net/TargetConnectionManager.java b/src/main/java/com/redhat/rhjmc/containerjfr/net/TargetConnectionManager.java index e3e19b3383..a66e4a6e85 100644 --- a/src/main/java/com/redhat/rhjmc/containerjfr/net/TargetConnectionManager.java +++ b/src/main/java/com/redhat/rhjmc/containerjfr/net/TargetConnectionManager.java @@ -132,7 +132,7 @@ private JFRConnection attemptConnectAsHostPortPair(ConnectionDescriptor connecti private JFRConnection connect(JMXServiceURL url, Optional credentials) throws Exception { - logger.trace(String.format("Locking connection %s", url.toString())); + logger.trace("Locking connection {}", url.toString()); lock.lockInterruptibly(); return jfrConnectionToolkit .get() @@ -141,11 +141,7 @@ private JFRConnection connect(JMXServiceURL url, Optional credentia credentials.orElse(null), List.of( lock::unlock, - () -> - logger.trace( - String.format( - "Unlocking connection %s", - url.toString())))); + () -> logger.trace("Unlocking connection {}", url.toString()))); } public interface ConnectedTask { diff --git a/src/main/java/com/redhat/rhjmc/containerjfr/net/reports/ActiveRecordingReportCache.java b/src/main/java/com/redhat/rhjmc/containerjfr/net/reports/ActiveRecordingReportCache.java index c031366a13..74a4a2d21a 100644 --- a/src/main/java/com/redhat/rhjmc/containerjfr/net/reports/ActiveRecordingReportCache.java +++ b/src/main/java/com/redhat/rhjmc/containerjfr/net/reports/ActiveRecordingReportCache.java @@ -116,10 +116,10 @@ boolean delete(ConnectionDescriptor connectionDescriptor, String recordingName) RecordingDescriptor key = new RecordingDescriptor(connectionDescriptor, recordingName); boolean hasKey = cache.asMap().containsKey(key); if (hasKey) { - logger.trace(String.format("Invalidated active report cache for %s", recordingName)); + logger.trace("Invalidated active report cache for {}", recordingName); cache.invalidate(key); } else { - logger.trace(String.format("No cache entry for %s to invalidate", recordingName)); + logger.trace("No cache entry for {} to invalidate", recordingName); } return hasKey; } @@ -128,9 +128,7 @@ protected String getReport(RecordingDescriptor recordingDescriptor) throws Excep Path saveFile = null; try { generationLock.lock(); - logger.trace( - String.format( - "Active report cache miss for %s", recordingDescriptor.recordingName)); + logger.trace("Active report cache miss for {}", recordingDescriptor.recordingName); try { saveFile = subprocessReportGeneratorProvider @@ -163,7 +161,7 @@ protected String getReport(RecordingDescriptor recordingDescriptor) throws Excep .findFirst(); if (clone.isPresent()) { conn.getService().close(clone.get()); - logger.trace("Cleaned dangling recording " + cloneName); + logger.trace("Cleaned dangling recording {}", cloneName); } return null; }); diff --git a/src/main/java/com/redhat/rhjmc/containerjfr/net/reports/ArchivedRecordingReportCache.java b/src/main/java/com/redhat/rhjmc/containerjfr/net/reports/ArchivedRecordingReportCache.java index f6d8a71220..cf57532914 100644 --- a/src/main/java/com/redhat/rhjmc/containerjfr/net/reports/ArchivedRecordingReportCache.java +++ b/src/main/java/com/redhat/rhjmc/containerjfr/net/reports/ArchivedRecordingReportCache.java @@ -103,10 +103,7 @@ Future get(String recordingName) { .findFirst() .ifPresentOrElse( recording -> { - logger.trace( - String.format( - "Archived report cache miss for %s", - recordingName)); + logger.trace("Archived report cache miss for {}", recordingName); try { Path saveFile = subprocessReportGeneratorProvider @@ -143,7 +140,7 @@ Future get(String recordingName) { boolean delete(String recordingName) { try { - logger.trace(String.format("Invalidating archived report cache for %s", recordingName)); + logger.trace("Invalidating archived report cache for {}", recordingName); return fs.deleteIfExists(getCachedReportPath(recordingName)); } catch (IOException ioe) { logger.warn(ioe); diff --git a/src/main/java/com/redhat/rhjmc/containerjfr/net/web/WebServer.java b/src/main/java/com/redhat/rhjmc/containerjfr/net/web/WebServer.java index 895d671951..bb67d5033a 100644 --- a/src/main/java/com/redhat/rhjmc/containerjfr/net/web/WebServer.java +++ b/src/main/java/com/redhat/rhjmc/containerjfr/net/web/WebServer.java @@ -195,9 +195,7 @@ public void start() throws FlightRecorderException, SocketException, UnknownHost } route = route.failureHandler(failureHandler); if (!handler.isAvailable()) { - logger.trace( - String.format( - "%s handler disabled", handler.getClass().getSimpleName())); + logger.trace("{} handler disabled", handler.getClass().getSimpleName()); route = route.disable(); } }); From b698237cbd7b907e785dd5ddc75c1beeae23c08c Mon Sep 17 00:00:00 2001 From: Alexander Senn Date: Thu, 17 Dec 2020 14:13:32 -0500 Subject: [PATCH 4/5] fix logger statement previously missed --- .../containerjfr/commands/internal/CommandRegistryImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/redhat/rhjmc/containerjfr/commands/internal/CommandRegistryImpl.java b/src/main/java/com/redhat/rhjmc/containerjfr/commands/internal/CommandRegistryImpl.java index 388eef12bd..0520fd0de0 100644 --- a/src/main/java/com/redhat/rhjmc/containerjfr/commands/internal/CommandRegistryImpl.java +++ b/src/main/java/com/redhat/rhjmc/containerjfr/commands/internal/CommandRegistryImpl.java @@ -104,7 +104,7 @@ public Output execute(String commandName, String[] args) { .getName() .equals(annotation.annotationType().getName())); if (deprecated) { - logger.warn(String.format("Command \"%s\" is deprecated", commandName)); + logger.warn("Command \"{}\" is deprecated", commandName); } return c.execute(args); } catch (Exception e) { From 86f8ef9f787c934a0a896c173e81bac86d2d2c18 Mon Sep 17 00:00:00 2001 From: Alexander Senn Date: Fri, 18 Dec 2020 10:04:58 -0500 Subject: [PATCH 5/5] Finish removing all string.format inside logger calls --- .../rhjmc/containerjfr/net/HttpServer.java | 11 +++++----- .../reports/SubprocessReportGenerator.java | 7 +++--- .../rhjmc/containerjfr/net/web/WebServer.java | 22 +++++++++---------- .../web/http/generic/HealthGetHandler.java | 3 +-- 4 files changed, 20 insertions(+), 23 deletions(-) diff --git a/src/main/java/com/redhat/rhjmc/containerjfr/net/HttpServer.java b/src/main/java/com/redhat/rhjmc/containerjfr/net/HttpServer.java index e6da552740..ec523c506d 100644 --- a/src/main/java/com/redhat/rhjmc/containerjfr/net/HttpServer.java +++ b/src/main/java/com/redhat/rhjmc/containerjfr/net/HttpServer.java @@ -108,12 +108,11 @@ public void start() throws SocketException, UnknownHostException { future.join(); // wait for async deployment to complete logger.info( - String.format( - "%s service running on %s://%s:%d", - isSsl() ? "HTTPS" : "HTTP", - isSsl() ? "https" : "http", - netConf.getWebServerHost(), - netConf.getExternalWebServerPort())); + "{} service running on {}://{}:{}", + isSsl() ? "HTTPS" : "HTTP", + isSsl() ? "https" : "http", + netConf.getWebServerHost(), + netConf.getExternalWebServerPort()); this.isAlive = true; } diff --git a/src/main/java/com/redhat/rhjmc/containerjfr/net/reports/SubprocessReportGenerator.java b/src/main/java/com/redhat/rhjmc/containerjfr/net/reports/SubprocessReportGenerator.java index 163adcf773..63d84cd317 100644 --- a/src/main/java/com/redhat/rhjmc/containerjfr/net/reports/SubprocessReportGenerator.java +++ b/src/main/java/com/redhat/rhjmc/containerjfr/net/reports/SubprocessReportGenerator.java @@ -260,10 +260,9 @@ public static void main(String[] args) { () -> { long elapsedTime = System.nanoTime() - startTime; Logger.INSTANCE.info( - String.format( - "%s shutting down after %dms", - SubprocessReportGenerator.class.getName(), - TimeUnit.NANOSECONDS.toMillis(elapsedTime))); + "{} shutting down after {}ms", + SubprocessReportGenerator.class.getName(), + TimeUnit.NANOSECONDS.toMillis(elapsedTime)); })); var fs = new FileSystem(); diff --git a/src/main/java/com/redhat/rhjmc/containerjfr/net/web/WebServer.java b/src/main/java/com/redhat/rhjmc/containerjfr/net/web/WebServer.java index bb67d5033a..9377ba039c 100644 --- a/src/main/java/com/redhat/rhjmc/containerjfr/net/web/WebServer.java +++ b/src/main/java/com/redhat/rhjmc/containerjfr/net/web/WebServer.java @@ -178,9 +178,10 @@ public void start() throws FlightRecorderException, SocketException, UnknownHost requestHandlers.forEach( handler -> { logger.trace( - String.format( - "Registering request handler (priority %d) for [%s]\t%s", - handler.getPriority(), handler.httpMethod(), handler.path())); + "Registering request handler (priority {}) for [{}]\t{}", + handler.getPriority(), + handler.httpMethod(), + handler.path()); Route route; if (RequestHandler.ALL_PATHS.equals(handler.path())) { route = router.route(); @@ -207,14 +208,13 @@ public void start() throws FlightRecorderException, SocketException, UnknownHost .endHandler( (res) -> logger.info( - String.format( - "(%s): %s %s %d %dms", - req.remoteAddress().toString(), - req.method().toString(), - req.path(), - req.response().getStatusCode(), - Duration.between(start, Instant.now()) - .toMillis()))); + "({}): {} {} {} {}ms", + req.remoteAddress().toString(), + req.method().toString(), + req.path(), + req.response().getStatusCode(), + Duration.between(start, Instant.now()) + .toMillis())); router.handle(req); }); } diff --git a/src/main/java/com/redhat/rhjmc/containerjfr/net/web/http/generic/HealthGetHandler.java b/src/main/java/com/redhat/rhjmc/containerjfr/net/web/http/generic/HealthGetHandler.java index 68e2f8fad9..b42c688c62 100644 --- a/src/main/java/com/redhat/rhjmc/containerjfr/net/web/http/generic/HealthGetHandler.java +++ b/src/main/java/com/redhat/rhjmc/containerjfr/net/web/http/generic/HealthGetHandler.java @@ -131,8 +131,7 @@ private void checkUri(String envName, String path, CompletableFuture fu future.complete(false); return; } - logger.debug( - String.format("Testing health of %s=%s %s", envName, uri.toString(), path)); + logger.debug("Testing health of {}={} {}", envName, uri.toString(), path); HttpRequest req = webClient.get(uri.getHost(), path); if (uri.getPort() != -1) { req = req.port(uri.getPort());