Repository: microsoftgraph/msgraph-sdk-java-core
Issue: Unable to change the loglevel for graph sdk

Hi Team,

I have enabled the DEBUG log using below code to debug the below error message:

Error message: Invalid batch payload format.

POST https://graph.microsoft.com/v1.0/$batch
SdkVersion : graph-java/v3.5.0
[...]

400 : Bad Request
[...]

[Some information was truncated for brevity, enable debug logging for more details]

Now I have enabled the debug mode using below code,
GraphServiceClient graphClient = graphClientBuilder.buildClient();
graphClient.getLogger().setLoggingLevel(LoggerLevel.DEBUG);

Now I am executing the batch request with 3.5.0 java SDK. I am not getting the debug statements. On debuging the source code i found BatchResponseStep class hard coded the verbose parameter with false by default.  Please guide me to enable verbose logging for batch requests.

Code snippet: 
throw GraphServiceException.createFromResponse("", "", new ArrayList<>(), "", headers, "", status, error, **false**); 
[AB#9533](https://microsoftgraph.visualstudio.com/0985d294-5762-4bc2-a565-161ef349ca3e/_workitems/edit/9533)

Changed files:
src/main/java/com/microsoft/graph/content/BatchResponseStep.java, src/test/java/com/microsoft/graph/content/BatchResponseContentTest.java, src/main/java/com/microsoft/graph/serializer/DefaultSerializer.java

diff --git a/src/main/java/com/microsoft/graph/content/BatchResponseStep.java b/src/main/java/com/microsoft/graph/content/BatchResponseStep.java
index feb1d13..6597613 100644
--- a/src/main/java/com/microsoft/graph/content/BatchResponseStep.java
+++ b/src/main/java/com/microsoft/graph/content/BatchResponseStep.java
@@ -33,6 +33,9 @@ import com.google.gson.annotations.SerializedName;
 import com.microsoft.graph.http.GraphErrorResponse;
 import com.microsoft.graph.http.GraphFatalServiceException;
 import com.microsoft.graph.http.GraphServiceException;
+import com.microsoft.graph.logger.ILogger;
+import com.microsoft.graph.logger.LoggerLevel;
+import com.microsoft.graph.serializer.DefaultSerializer;
 import com.microsoft.graph.serializer.ISerializer;
 
 /** Response for the batch step */
@@ -61,7 +64,13 @@ public class BatchResponseStep<T> extends BatchStep<T> {
         final GraphErrorResponse error = serializer.deserializeObject((JsonElement)body, GraphErrorResponse.class);
         if(error == null || error.error == null) {
             return serializer.deserializeObject((JsonElement)body, resultClass);
-        } else
-            throw GraphServiceException.createFromResponse("", "", new ArrayList<>(), "", headers, "", status, error, false);
+        } else {
+            boolean verboseError = false;
+            if(serializer instanceof DefaultSerializer) {
+                final ILogger logger = ((DefaultSerializer)serializer).getLogger();
+                verboseError = logger != null && logger.getLoggingLevel() == LoggerLevel.DEBUG;
+            }
+            throw GraphServiceException.createFromResponse("", "", new ArrayList<>(), "", headers, "", status, error, verboseError);
+        }
     }
 }
diff --git a/src/main/java/com/microsoft/graph/serializer/DefaultSerializer.java b/src/main/java/com/microsoft/graph/serializer/DefaultSerializer.java
index bf520e2..ec9f799 100644
--- a/src/main/java/com/microsoft/graph/serializer/DefaultSerializer.java
+++ b/src/main/java/com/microsoft/graph/serializer/DefaultSerializer.java
@@ -393,7 +393,6 @@ public class DefaultSerializer implements ISerializer {
 	 *
 	 * @return a logger
 	 */
-	@VisibleForTesting
 	@Nullable
 	public ILogger getLogger() {
 		return logger;
diff --git a/src/test/java/com/microsoft/graph/content/BatchResponseContentTest.java b/src/test/java/com/microsoft/graph/content/BatchResponseContentTest.java
index 6414b72..a39b925 100644
--- a/src/test/java/com/microsoft/graph/content/BatchResponseContentTest.java
+++ b/src/test/java/com/microsoft/graph/content/BatchResponseContentTest.java
@@ -14,7 +14,9 @@ import java.util.Iterator;
 import com.google.gson.JsonElement;
 import com.microsoft.graph.http.GraphErrorResponse;
 import com.microsoft.graph.http.GraphServiceException;
+import com.microsoft.graph.logger.DefaultLogger;
 import com.microsoft.graph.logger.ILogger;
+import com.microsoft.graph.logger.LoggerLevel;
 import com.microsoft.graph.serializer.DefaultSerializer;
 import com.microsoft.graph.serializer.ISerializer;
 
@@ -114,4 +116,52 @@ public class BatchResponseContentTest {
         } else
             fail("batch response was null");
     }
+    @Test
+    public void includeVerboseInformation() {
+        String responsebody = "{\\"responses\\":[{\\"id\\":\\"1\\",\\"status\\":400,\\"headers\\":{\\"Cache-Control\\":\\"no-cache\\",\\"x-ms-resource-unit\\":\\"1\\",\\"Content-Type\\":\\"application/json\\"},\\"body\\":{\\"error\\":{\\"code\\":\\"Request_BadRequest\\",\\"message\\":\\"Avalueisrequiredforproperty'displayName'ofresource'User'.\\",\\"innerError\\":{\\"date\\":\\"2021-02-02T19:19:38\\",\\"request-id\\":\\"408b8e64-4047-4c97-95b6-46e9f212ab48\\",\\"client-request-id\\":\\"102910da-260c-3028-0fb3-7d6903a02622\\"}}}}]}";
+        ISerializer serializer = new DefaultSerializer(new DefaultLogger() {{
+            setLoggingLevel(LoggerLevel.DEBUG);
+        }});
+        BatchResponseContent batchresponse = serializer.deserializeObject(responsebody, BatchResponseContent.class);
+        if(batchresponse != null) {
+            if(batchresponse.responses != null)  // this is done by the batch request in the fluent API
+                for(final BatchResponseStep<?> step : batchresponse.responses) {
+                    step.serializer = serializer;
+                }
+            try {
+                batchresponse.getResponseById("1").getDeserializedBody(BatchRequestContent.class);
+            } catch(GraphServiceException ex) {
+                final GraphErrorResponse response = ex.getError();
+                assertNotNull(response);
+                assertNotNull(response.error);
+                assertNotNull(response.error.message);
+                assertEquals(ex.getMessage(true), ex.getMessage());
+            }
+        } else
+            fail("batch response was null");
+    }
+    @Test
+    public void doesNotIncludeVerboseInformation() {
+        String responsebody = "{\\"responses\\":[{\\"id\\":\\"1\\",\\"status\\":400,\\"headers\\":{\\"Cache-Control\\":\\"no-cache\\",\\"x-ms-resource-unit\\":\\"1\\",\\"Content-Type\\":\\"application/json\\"},\\"body\\":{\\"error\\":{\\"code\\":\\"Request_BadRequest\\",\\"message\\":\\"Avalueisrequiredforproperty'displayName'ofresource'User'.\\",\\"innerError\\":{\\"date\\":\\"2021-02-02T19:19:38\\",\\"request-id\\":\\"408b8e64-4047-4c97-95b6-46e9f212ab48\\",\\"client-request-id\\":\\"102910da-260c-3028-0fb3-7d6903a02622\\"}}}}]}";
+        ISerializer serializer = new DefaultSerializer(new DefaultLogger() {{
+            setLoggingLevel(LoggerLevel.ERROR);
+        }});
+        BatchResponseContent batchresponse = serializer.deserializeObject(responsebody, BatchResponseContent.class);
+        if(batchresponse != null) {
+            if(batchresponse.responses != null)  // this is done by the batch request in the fluent API
+                for(final BatchResponseStep<?> step : batchresponse.responses) {
+                    step.serializer = serializer;
+                }
+            try {
+                batchresponse.getResponseById("1").getDeserializedBody(BatchRequestContent.class);
+            } catch(GraphServiceException ex) {
+                final GraphErrorResponse response = ex.getError();
+                assertNotNull(response);
+                assertNotNull(response.error);
+                assertNotNull(response.error.message);
+                assertEquals(ex.getMessage(false), ex.getMessage());
+            }
+        } else
+            fail("batch response was null");
+    }
 }