From 6bd7af96c11871e5a6c0ceb245234fc3b0fd4ca6 Mon Sep 17 00:00:00 2001 From: "manoj.kumar" Date: Fri, 10 Jul 2026 13:36:36 +0530 Subject: [PATCH] fix: replace System.out/err prints with SLF4J logger in OllamaBaseLM --- .../com/google/adk/models/OllamaBaseLM.java | 29 +++++++------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/core/src/main/java/com/google/adk/models/OllamaBaseLM.java b/core/src/main/java/com/google/adk/models/OllamaBaseLM.java index 99d0772e0..cdd7834a9 100644 --- a/core/src/main/java/com/google/adk/models/OllamaBaseLM.java +++ b/core/src/main/java/com/google/adk/models/OllamaBaseLM.java @@ -180,10 +180,7 @@ public Flowable generateContent(LlmRequest llmRequest, boolean stre // Skip this tool if there is no function declaration if (!declarationOptional.isPresent()) { - // Log a warning or handle appropriately - System.err.println( - "Skipping tool '" + baseTool.name() + "' with missing declaration."); - // continue; // If inside a loop + logger.warn("Skipping tool '{}' with missing declaration.", baseTool.name()); return; // If processing a single tool outside a loop } @@ -388,8 +385,7 @@ public Flowable generateContentStream(LlmRequest llmRequest) { BaseTool baseTool = tooldetail.getValue(); Optional declarationOptional = baseTool.declaration(); if (!declarationOptional.isPresent()) { - System.err.println( - "Skipping tool '" + baseTool.name() + "' with missing declaration."); + logger.warn("Skipping tool '{}' with missing declaration.", baseTool.name()); return; } FunctionDeclaration functionDeclaration = declarationOptional.get(); @@ -697,7 +693,7 @@ public BufferedReader callLLMChatStream(String model, JSONArray messages, JSONAr } int responseCode = connection.getResponseCode(); - System.out.println("Response Code from Ollama for model " + model + ": " + responseCode); + logger.debug("Response Code from Ollama for model {}: {}", model, responseCode); if (responseCode >= 200 && responseCode < 300) { return new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8")); @@ -710,7 +706,7 @@ public BufferedReader callLLMChatStream(String model, JSONArray messages, JSONAr while ((errorLine = errorReader.readLine()) != null) { errorResponse.append(errorLine); } - System.err.println("Error Response Body: " + errorResponse.toString()); + logger.error("Error Response Body: {}", errorResponse.toString()); } catch (IOException errorEx) { logger.error("Error reading error stream", errorEx); } @@ -890,7 +886,7 @@ public JSONObject callLLMChat( // Read response int responseCode = connection.getResponseCode(); - System.out.println("Response Code: " + responseCode); + logger.debug("Response Code: {}", responseCode); // Read response body using UTF-8 try (InputStream inputStream = connection.getInputStream(); @@ -901,7 +897,7 @@ public JSONObject callLLMChat( while ((line = reader.readLine()) != null) { response.append(line); } - System.out.println("Response Body: " + response.toString()); + logger.debug("Response Body: {}", response.toString()); responseJ = new JSONObject(response.toString()); @@ -917,7 +913,7 @@ public JSONObject callLLMChat( while ((errorLine = errorReader.readLine()) != null) { errorResponse.append(errorLine); } - System.err.println("Error Response Body: " + errorResponse.toString()); + logger.error("Error Response Body: {}", errorResponse.toString()); // You might want to parse the errorResponse as a JSON object too if the API returns // JSON errors } catch (IOException errorEx) { @@ -988,7 +984,7 @@ public static JSONObject callLLMChat( // Open connection HttpURLConnection connection = (HttpURLConnection) url.openConnection(); - System.out.print("HTTP Connection to Ollama API: " + apiUrl.toString()); + logger.debug("HTTP Connection to Ollama API: {}", apiUrl); // Set request method connection.setRequestMethod("POST"); @@ -1007,7 +1003,7 @@ public static JSONObject callLLMChat( // Read response int responseCode = connection.getResponseCode(); - System.out.println("Response Code: " + responseCode); + logger.debug("Response Code: {}", responseCode); // Read response body try (BufferedReader reader = @@ -1032,10 +1028,7 @@ public static JSONObject callLLMChat( streamOutput.append(responseText); // Display the parsed data - System.out.println("Model: " + model); - System.out.println("Response Text: " + responseText); - System.out.println("Done: " + done); - System.out.println("----------"); + logger.debug("Model: {}, Response Text: {}, Done: {}", model, responseText, done); // Break if response is marked as done if (done) { @@ -1056,7 +1049,7 @@ public static JSONObject callLLMChat( response.append(line); } String responseBody = response.toString(); - System.out.println("Response Body: " + responseBody); + logger.debug("Response Body: {}", responseBody); responseJ = new JSONObject(responseBody); }