Updating grpc ctrl to log message on log level DEBUG

Change-Id: Ie78702995b24fb3e579914843bd8f9738d6ad3cc
diff --git a/protocols/grpc/ctl/src/main/java/org/onosproject/grpc/ctl/GrpcControllerImpl.java b/protocols/grpc/ctl/src/main/java/org/onosproject/grpc/ctl/GrpcControllerImpl.java
index 91b9db0..db58575 100644
--- a/protocols/grpc/ctl/src/main/java/org/onosproject/grpc/ctl/GrpcControllerImpl.java
+++ b/protocols/grpc/ctl/src/main/java/org/onosproject/grpc/ctl/GrpcControllerImpl.java
@@ -65,10 +65,6 @@
 @Service
 public class GrpcControllerImpl implements GrpcController {
 
-    // Hint: set to true to log all gRPC messages received/sent on all channels.
-    // TODO: make configurable at runtime
-    public static boolean enableMessageLog = false;
-
     private static final int CONNECTION_TIMEOUT_SECONDS = 20;
 
     public static final Logger log = LoggerFactory
@@ -123,9 +119,7 @@
         lock.lock();
 
         try {
-            if (enableMessageLog) {
-                channelBuilder.intercept(new InternalLogChannelInterceptor(channelId));
-            }
+            channelBuilder.intercept(new InternalLogChannelInterceptor(channelId));
             ManagedChannel channel = channelBuilder.build();
             // Forced connection not yet implemented. Use workaround...
             // channel.getState(true);
@@ -254,8 +248,13 @@
 
                 @Override
                 public void sendMessage(ReqT message) {
-                    log.info("*** SENDING GRPC MESSAGE [{}]\n{}:\n{}", channelId, methodDescriptor.getFullMethodName(),
-                             message.toString());
+                    if (log.isDebugEnabled()) {
+                        String m = message.toString();
+                        // Don't print message contents over 20kb unless trace is enabled
+                        m = m.length() < 20_000 || log.isTraceEnabled() ? m : String.format("<%d bytes>", m.length());
+                        log.debug("*** SENDING GRPC MESSAGE [{}]\n{}:\n{}", channelId,
+                                  methodDescriptor.getFullMethodName(), m);
+                    }
                     super.sendMessage(message);
                 }
 
@@ -270,9 +269,11 @@
 
                         @Override
                         public void onMessage(RespT message) {
-                            log.info("*** RECEIVED GRPC MESSAGE [{}]\n{}:\n{}", channelId,
-                                     methodDescriptor.getFullMethodName(),
-                                     message.toString());
+                            if (log.isDebugEnabled()) {
+                                log.debug("*** RECEIVED GRPC MESSAGE [{}]\n{}:\n{}", channelId,
+                                          methodDescriptor.getFullMethodName(),
+                                          message.toString());
+                            }
                             super.onMessage(message);
                         }
                     };