Fix pull-replication after the removal of Log4J from Gerrit

Utilize Flogger's logging tag feature instead of the Log4J's MDC.
This is needed after the removal of Log4J by I1d01ab0a5d3ad.

The solution is aligned with the equivalent change on the
replication plugin I0d18f89312e31.

A small disadvantage is that the trace context is a part of the
log message i.e. we cannot really control the layout. What was earlier:

[2020-05-04 ...] [c0b3774c] Missing repository could not be created when replicating <repo-url>

becomes now:

[2020-05-04 ...] Missing repository could not be created when replicating <repo-url> [CONTEXT PLUGIN="replication" fetchOneId="c0b3774c" ]

Bug: Issue 15579
Change-Id: I07f2cab60c4695390bd7b4ce6db9e71053d6758b
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/FetchOne.java b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/FetchOne.java
index d4e22d9..32dfe46 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/FetchOne.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/FetchOne.java
@@ -28,6 +28,7 @@
 import com.google.gerrit.server.git.ProjectRunnable;
 import com.google.gerrit.server.git.WorkQueue.CanceledWhileRunning;
 import com.google.gerrit.server.ioutil.HexFormat;
+import com.google.gerrit.server.logging.TraceContext;
 import com.google.gerrit.server.util.IdGenerator;
 import com.google.inject.Inject;
 import com.google.inject.assistedinject.Assisted;
@@ -54,7 +55,6 @@
 import org.eclipse.jgit.transport.RefSpec;
 import org.eclipse.jgit.transport.RemoteConfig;
 import org.eclipse.jgit.transport.URIish;
-import org.slf4j.MDC;
 
 /**
  * A pull from remote operation started by command-line.
@@ -65,7 +65,7 @@
 public class FetchOne implements ProjectRunnable, CanceledWhileRunning {
   private final ReplicationStateListener stateLog;
   static final String ALL_REFS = "..all..";
-  static final String ID_MDC_KEY = "fetchOneId";
+  static final String ID_KEY = "fetchOneId";
 
   interface Factory {
     FetchOne create(Project.NameKey d, URIish u);
@@ -270,11 +270,16 @@
   }
 
   private void runFetchOperation() {
+    try (TraceContext ctx = TraceContext.open().addTag(ID_KEY, HexFormat.fromInt(id))) {
+      doRunFetchOperation();
+    }
+  }
+
+  private void doRunFetchOperation() {
     // Lock the queue, and remove ourselves, so we can't be modified once
     // we start replication (instead a new instance, with the same URI, is
     // created and scheduled for a future point in time.)
     //
-    MDC.put(ID_MDC_KEY, HexFormat.fromInt(id));
     if (!pool.requestRunway(this)) {
       if (!canceled) {
         repLog.info(
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/PullReplicationLogFile.java b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/PullReplicationLogFile.java
index 299648d..932103b 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/PullReplicationLogFile.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/PullReplicationLogFile.java
@@ -28,6 +28,6 @@
         systemLog,
         serverInfo,
         PullReplicationLogger.PULL_REPLICATION_LOG_NAME,
-        new PatternLayout("[%d] [%X{" + FetchOne.ID_MDC_KEY + "}] %m%n"));
+        new PatternLayout("[%d] %m%n"));
   }
 }