Avoid string concatenation in Flogger log statements Move shared log message prefixes into log arguments instead of concatenating them at logging sites. This keeps format placeholders and arguments validated by Flogger while preserving the existing logging behavior for multi-primary setups. Change-Id: I09d97fa45a294b0f42fec43d935f3597f3cbcf7b
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationTasksStorage.java b/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationTasksStorage.java index b60cc57..7fc4acb 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationTasksStorage.java +++ b/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationTasksStorage.java
@@ -226,12 +226,13 @@ } catch (NotDirectoryException e) { return Stream.of(path); } catch (Exception e) { - String message = "Error while walking directory %s"; + String message = "Error while walking directory"; if (isMultiPrimary() && e instanceof NoSuchFileException) { logger.atFine().log( - message + " (expected regularly with multi-primaries and distributor enabled)", path); + "%s %s (expected regularly with multi-primaries and distributor enabled)", + message, path); } else { - logger.atSevere().withCause(e).log(message, path); + logger.atSevere().withCause(e).log("%s %s", message, path); } return Stream.empty(); } @@ -401,15 +402,14 @@ logger.atFine().log("DELETE %s %s", running, updateLog()); Files.delete(running); } catch (IOException e) { - String message = "Error while deleting task %s"; + String message = "Error while deleting task"; if (isMultiPrimary() && e instanceof NoSuchFileException) { logger.atFine().log( - message - + " (expected after recovery from another node's startup with multi-primaries and" + "%s %s (expected after recovery from another node's startup with multi-primaries and" + " distributor enabled)", - taskKey); + message, taskKey); } else { - logger.atSevere().withCause(e).log(message, taskKey); + logger.atSevere().withCause(e).log("%s %s", message, taskKey); } } } @@ -421,13 +421,13 @@ Files.move(from, to, StandardCopyOption.ATOMIC_MOVE, StandardCopyOption.REPLACE_EXISTING); return true; } catch (IOException e) { - String message = "Error while renaming task %s"; + String message = "Error while renaming task"; if (isMultiPrimary() && e instanceof NoSuchFileException) { logger.atFine().log( - message + " (expected regularly with multi-primaries and distributor enabled)", - taskKey); + "%s %s (expected regularly with multi-primaries and distributor enabled)", + message, taskKey); } else { - logger.atSevere().withCause(e).log(message, taskKey); + logger.atSevere().withCause(e).log("%s %s", message, taskKey); } return false; }