Flogger: Arguments to log(String) must be compile-time constants

Remove static MSG() method, that added name of properties file to log
message. Instead add the AMQP URL to the log message.

Change-Id: If526bf059fddca4f2cc03c92d1f7ddba6453b6d9
diff --git a/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/Manager.java b/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/Manager.java
index 55b0929..8290d05 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/Manager.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/Manager.java
@@ -114,7 +114,7 @@
         }
       }
     } catch (IOException ioe) {
-      logger.atWarning().log(ioe.getMessage());
+      logger.atWarning().withCause(ioe).log("Failed to load properties.");
     }
     if (propList.isEmpty()) {
       logger.atWarning().log("No site configs found. Using base config only!");
diff --git a/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/session/type/AMQPSession.java b/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/session/type/AMQPSession.java
index cc58b3c..5b2e0d2 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/session/type/AMQPSession.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/session/type/AMQPSession.java
@@ -49,10 +49,6 @@
     this.properties = properties;
   }
 
-  private String MSG(String msg) {
-    return String.format("[%s] %s", properties.getName(), msg);
-  }
-
   @Override
   public boolean isOpen() {
     if (connection != null && connection.isOpen()) {
@@ -65,28 +61,30 @@
     if (!isOpen()) {
       connect();
     } else {
+      AMQP amqp = properties.getSection(AMQP.class);
       try {
         Channel ch = connection.createChannel();
         int channelId = ch.getChannelNumber();
         ch.addShutdownListener(
             cause -> {
               if (cause.isInitiatedByApplication()) {
-                logger.atInfo().log(MSG("Channel #%d closed by application."), channelId);
+                logger.atInfo().log("Channel #%d closed by application.", channelId);
               } else {
                 logger.atWarning().log(
-                    MSG("Channel #%d closed. Cause: %s"), channelId, cause.getMessage());
+                    "Channel #%d closed. Cause: %s", channelId, cause.getMessage());
               }
             });
         failureCount.set(0);
-        logger.atInfo().log(MSG("Channel #%d opened."), channelId);
+        logger.atInfo().log("Channel #%d opened for %s.", channelId, amqp.uri);
         return ch;
       } catch (IOException | AlreadyClosedException ex) {
-        logger.atSevere().withCause(ex).log(MSG("Failed to open channel."));
+        logger.atSevere().withCause(ex).log("Failed to open channel for %s.", amqp.uri);
         failureCount.incrementAndGet();
       }
       if (failureCount.get() > properties.getSection(Monitor.class).failureCount) {
         logger.atWarning().log(
-            "Creating channel failed %d times, closing connection.", failureCount.get());
+            "Creating channel failed %d times, closing connection %s.",
+            failureCount.get(), amqp.uri);
         disconnect();
       }
     }
@@ -95,12 +93,12 @@
 
   @Override
   public boolean connect() {
+    AMQP amqp = properties.getSection(AMQP.class);
     if (isOpen()) {
-      logger.atInfo().log(MSG("Already connected."));
+      logger.atInfo().log("Already connected to %s.", amqp.uri);
       return true;
     }
-    AMQP amqp = properties.getSection(AMQP.class);
-    logger.atInfo().log(MSG("Connect to %s..."), amqp.uri);
+    logger.atInfo().log("Connect to %s...", amqp.uri);
     ConnectionFactory factory = new ConnectionFactory();
     try {
       if (StringUtils.isNotEmpty(amqp.uri)) {
@@ -119,45 +117,46 @@
         connection.addShutdownListener(
             cause -> {
               if (cause.isInitiatedByApplication()) {
-                logger.atInfo().log(MSG("Connection closed by application."));
+                logger.atInfo().log("Connection closed by application.");
               } else {
-                logger.atWarning().log(MSG("Connection closed. Cause: %s"), cause.getMessage());
+                logger.atWarning().log("Connection closed. Cause: %s", cause.getMessage());
               }
             });
-        logger.atInfo().log(MSG("Connection established."));
+        logger.atInfo().log("Connection established to %s.", amqp.uri);
         return true;
       }
     } catch (URISyntaxException ex) {
-      logger.atSevere().log(MSG("URI syntax error: %s"), amqp.uri);
+      logger.atSevere().log("URI syntax error: %s", amqp.uri);
     } catch (IOException | TimeoutException ex) {
-      logger.atSevere().withCause(ex).log(MSG("Connection cannot be opened."));
+      logger.atSevere().withCause(ex).log("Connection to %s cannot be opened.", amqp.uri);
     } catch (KeyManagementException | NoSuchAlgorithmException ex) {
-      logger.atSevere().withCause(ex).log(MSG("Security error when opening connection."));
+      logger.atSevere().withCause(ex).log(
+          "Security error when opening connection to %s.", amqp.uri);
     }
     return false;
   }
 
   @Override
   public void disconnect() {
-    logger.atInfo().log(MSG("Disconnecting..."));
+    logger.atInfo().log("Disconnecting...");
     try {
       if (channel != null) {
-        logger.atInfo().log(MSG("Closing Channel #%d..."), channel.getChannelNumber());
+        logger.atInfo().log("Closing Channel #%d...", channel.getChannelNumber());
         channel.close();
       }
     } catch (IOException | TimeoutException ex) {
-      logger.atSevere().withCause(ex).log(MSG("Error when closing channel."));
+      logger.atSevere().withCause(ex).log("Error when closing channel.");
     } finally {
       channel = null;
     }
 
     try {
       if (connection != null) {
-        logger.atInfo().log(MSG("Closing Connection..."));
+        logger.atInfo().log("Closing Connection...");
         connection.close();
       }
     } catch (IOException | ShutdownSignalException ex) {
-      logger.atWarning().withCause(ex).log(MSG("Error when closing connection."));
+      logger.atWarning().withCause(ex).log("Error when closing connection.");
     } finally {
       connection = null;
     }
@@ -172,7 +171,7 @@
       Message message = properties.getSection(Message.class);
       Exchange exchange = properties.getSection(Exchange.class);
       try {
-        logger.atFine().log(MSG("Sending message."));
+        logger.atFine().log("Sending message.");
         channel.basicPublish(
             exchange.name,
             message.routingKey,
@@ -180,11 +179,11 @@
             messageBody.getBytes(CharEncoding.UTF_8));
         return true;
       } catch (IOException ex) {
-        logger.atSevere().withCause(ex).log(MSG("Error when sending meessage."));
+        logger.atSevere().withCause(ex).log("Error when sending meessage.");
         return false;
       }
     }
-    logger.atSevere().log(MSG("Cannot open channel."));
+    logger.atSevere().log("Cannot open channel.");
     return false;
   }
 }