Quellcode durchsuchen

Merge pull request #101 from sahuang/master

Use SLF4J and Log4j2 for Logging
Xiaohai Xu vor 5 Jahren
Ursprung
Commit
385fe72c18

+ 23 - 37
CHANGELOG.md

@@ -1,21 +1,28 @@
 # Changelog     
 
+## milvus-sdk-java 0.8.0 (2020-05-15)
+
+### Feature
+
+- \#93 - Add/Improve getVectorByID, collectionInfo and hasPartition API
+- \#2295 - Rename SDK interfaces
+
 ## milvus-sdk-java 0.7.0 (2020-04-15)
 
-## Feature
----
+### Feature
+
 - \#261 - Integrate ANNOY into Milvus
 - \#1828 - Add searchAsync / createIndexAsync / insertAsync / flushAsync / compactAsync API
 
 ## milvus-sdk-java 0.6.0 (2020-03-31)
 
 ### Bug
----
+
 - \#1641 - Fix incorrect error logging message
 - \#1642 - Fix compilation error of ByteBuffer
 
-## Feature
----
+### Feature
+
 - \#1603 - Add binary metrics: Substructure & Superstructure
 
 ## milvus-sdk-java 0.5.0 (2020-03-11)
@@ -23,72 +30,51 @@
 ## milvus-sdk-java 0.4.1 (2019-12-16)
 
 ### Bug
----
+
 - \#78 - Partition tag not working when searching
 
 ## milvus-sdk-java 0.4.0 (2019-12-7)
 
 ### Bug
----
+
 - \#74 - Partition tag not working when inserting
 
 ### Improvement
----
+
 - \#61 - Add partition
 - \#70 - Add IndexType IVF_PQ
 - \#72 - Add more getters in ShowPartitionResponse
 - \#73 - Add @Deprecated for DateRanges in SearchParam
 
-### Feature
----
-
-### Task
----
-
 ## milvus-sdk-java 0.3.0 (2019-11-13)
 
 ### Bug
----
+
 - \#64 - Search failed with exception if search result is empty
 
 ### Improvement
----
+
 - \#56 - Add keepalive and idleTimeout settings
 - \#57 - add ok() in other types of Response
 - \#62 - Change GRPC proto (and related code) to increase search result's transmission speed
 - \#63 - Make some functions and constructors package-private if necessary
 
-### Feature
----
-
-### Task
----
-
 ## milvus-sdk-java 0.2.2 (2019-11-4)
 
-### Bug
----
-
 ### Improvement
----
+
 - \#49 - Add waitTime option in ConnectParam
 - \#51 - Change connect waitTime to timeout
 - \#52 - Change IVF_SQ8H to IVF_SQ8_H
 
-### Feature
----
-
-### Task
----
-
 ## milvus-sdk-java 0.2.0 (2019-10-21)
 
 ### Bug
----
+
 - \#42 - fix search result validation
     
 ### Improvement
----
+
 - \#3 - Force channel to request connection in connect()  and some code cleanup
 - \#6 - Update pom & fix deleteByRange error message & update unittest
 - \#8 - change default timeout to 24 hour
@@ -101,12 +87,12 @@
 - \#38 - Update examples
 - \#40 - Remove timeout parameter & Several API changes    
 
-### New Feature
----
+### Feature
+
 - \#16 - add IVF_SQ8_H index type
 
 ### Task
----
+
 - \#1 - First implementation
 - \#21 - Add javadoc
 - \#23 - Format code with Google-java-style and add Apache 2.0 license header

+ 24 - 0
README.md

@@ -23,6 +23,7 @@ The following table shows compatibilities between Milvus and Java SDK.
    |     0.7.0      |    0.5.0    |
    |     0.7.1      |    0.6.0    |
    |     0.8.0      |    0.7.0    |
+   |     0.9.0      |    0.8.0    |
 
 ### Install Java SDK
 
@@ -55,3 +56,26 @@ Please refer to [examples](https://github.com/milvus-io/milvus-sdk-java/tree/mas
 ### Additional information
 
 - The Java source code is formatted using [google-java-format](https://github.com/google/google-java-format).
+- If you receive the following error when running your application:
+    ```
+    Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
+    ```
+  This is because SLF4J jar file needs to be added into your application's classpath.
+  
+  To fix this issue, you can use **Apache Maven** or **Gradle**/**Grails** to download the required jar files.
+                                                                                                         
+    - Apache Maven
+ 
+        ```xml
+         <dependency>
+             <groupId>org.slf4j</groupId>
+             <artifactId>slf4j-api</artifactId>
+             <version>1.7.30</version>
+         </dependency>
+        ```
+ 
+    - Gradle/Grails
+ 
+         ```gradle
+         compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.30'
+         ```

+ 6 - 1
examples/pom.xml

@@ -25,7 +25,7 @@
 
     <groupId>io.milvus</groupId>
     <artifactId>milvus-sdk-java-examples</artifactId>
-    <version>0.5.0</version>
+    <version>0.8.0</version>
     <build>
         <plugins>
             <plugin>
@@ -70,6 +70,11 @@
             <artifactId>gson</artifactId>
             <version>2.8.6</version>
         </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+            <version>1.7.30</version>
+        </dependency>
     </dependencies>
 
 </project>

+ 1 - 4
examples/src/main/java/MilvusClientExample.java

@@ -25,7 +25,6 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.SplittableRandom;
 import java.util.concurrent.ExecutionException;
-import java.util.logging.Level;
 import java.util.stream.Collectors;
 import java.util.stream.DoubleStream;
 
@@ -69,9 +68,7 @@ public class MilvusClientExample {
     }
 
     // Create Milvus client
-    // You can specify the log level. Currently we have three levels of logs: INFO, WARNING and
-    // SEVERE
-    MilvusClient client = new MilvusGrpcClient(Level.ALL);
+    MilvusClient client = new MilvusGrpcClient();
 
     // Connect to Milvus server
     ConnectParam connectParam = new ConnectParam.Builder().withHost(host).withPort(port).build();

+ 10 - 0
pom.xml

@@ -150,6 +150,16 @@
             <artifactId>json</artifactId>
             <version>20190722</version>
         </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+            <version>1.7.30</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.logging.log4j</groupId>
+            <artifactId>log4j-slf4j-impl</artifactId>
+            <version>2.12.1</version>
+        </dependency>
 
     </dependencies>
 

+ 0 - 1
src/main/java/io/milvus/client/GetVectorsByIdsResponse.java

@@ -2,7 +2,6 @@ package io.milvus.client;
 
 import java.nio.ByteBuffer;
 import java.util.List;
-import java.util.Optional;
 
 /**
  * Contains the returned <code>response</code> and either a <code>List</code> of <code>floatVectors</code> or <code>

+ 116 - 129
src/main/java/io/milvus/client/MilvusGrpcClient.java

@@ -29,7 +29,6 @@ import io.grpc.ManagedChannel;
 import io.grpc.ManagedChannelBuilder;
 import io.grpc.StatusRuntimeException;
 import io.milvus.grpc.*;
-import org.apache.commons.collections4.ListUtils;
 
 import javax.annotation.Nonnull;
 import java.nio.Buffer;
@@ -38,13 +37,13 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.TimeUnit;
 import java.util.function.Function;
-import java.util.logging.Level;
-import java.util.logging.Logger;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /** Actual implementation of interface <code>MilvusClient</code> */
 public class MilvusGrpcClient implements MilvusClient {
 
-  private static final Logger logger = Logger.getLogger(MilvusGrpcClient.class.getName());
+  private static final Logger logger = LoggerFactory.getLogger(MilvusGrpcClient.class);
   private static final String ANSI_RESET = "\u001B[0m";
   private static final String ANSI_YELLOW = "\u001B[33m";
   private static final String ANSI_PURPLE = "\u001B[35m";
@@ -55,19 +54,7 @@ public class MilvusGrpcClient implements MilvusClient {
   private MilvusServiceGrpc.MilvusServiceFutureStub futureStub = null;
 
   ////////////////////// Constructor //////////////////////
-  public MilvusGrpcClient() {
-    logger.setLevel(Level.ALL);
-  }
-
-  /**
-   * @param logLevel we currently have three levels of logs: <code>INFO</code>, <code>WARNING</code>
-   *     and <code>SEVERE</code>. You can also specify to be <code>Level.All</code> or <code>
-   *     Level.OFF</code>
-   * @see Level
-   */
-  public MilvusGrpcClient(Level logLevel) {
-    logger.setLevel(logLevel);
-  }
+  public MilvusGrpcClient() {}
 
   /////////////////////// Client Calls///////////////////////
 
@@ -95,12 +82,12 @@ public class MilvusGrpcClient implements MilvusClient {
       channel.getState(true);
 
       long timeout = connectParam.getConnectTimeout(TimeUnit.MILLISECONDS);
-      logInfo("Trying to connect...Timeout in {0} ms", timeout);
+      logInfo("Trying to connect...Timeout in {} ms", timeout);
 
       final long checkFrequency = 100; // ms
       while (channel.getState(false) != ConnectivityState.READY) {
         if (timeout <= 0) {
-          logSevere("Connect timeout!");
+          logError("Connect timeout!");
           throw new ConnectFailedException("Connect timeout");
         }
         TimeUnit.MILLISECONDS.sleep(checkFrequency);
@@ -112,13 +99,13 @@ public class MilvusGrpcClient implements MilvusClient {
 
     } catch (Exception e) {
       if (!(e instanceof ConnectFailedException)) {
-        logSevere("Connect failed! {0}", e.toString());
+        logError("Connect failed! {}", e.toString());
       }
       throw new ConnectFailedException("Exception occurred: " + e.toString());
     }
 
     logInfo(
-        "Connection established successfully to host={0}, port={1}",
+        "Connection established successfully to host={}, port={}",
         connectParam.getHost(), String.valueOf(connectParam.getPort()));
     return new Response(Response.Status.SUCCESS);
   }
@@ -142,11 +129,11 @@ public class MilvusGrpcClient implements MilvusClient {
         if (channel.shutdown().awaitTermination(60, TimeUnit.SECONDS)) {
           logInfo("Channel terminated");
         } else {
-          logSevere("Encountered error when terminating channel");
+          logError("Encountered error when terminating channel");
           return new Response(Response.Status.RPC_ERROR);
         }
       } catch (InterruptedException e) {
-        logSevere("Exception thrown when terminating channel: {0}", e.toString());
+        logError("Exception thrown when terminating channel: {}", e.toString());
         throw e;
       }
     }
@@ -175,21 +162,21 @@ public class MilvusGrpcClient implements MilvusClient {
       response = blockingStub.createCollection(request);
 
       if (response.getErrorCode() == ErrorCode.SUCCESS) {
-        logInfo("Created collection successfully!\n{0}", collectionMapping.toString());
+        logInfo("Created collection successfully!\n{}", collectionMapping.toString());
         return new Response(Response.Status.SUCCESS);
       } else if (response.getReason().contentEquals("Collection already exists")) {
-        logWarning("Collection `{0}` already exists", collectionMapping.getCollectionName());
+        logWarning("Collection `{}` already exists", collectionMapping.getCollectionName());
         return new Response(
             Response.Status.valueOf(response.getErrorCodeValue()), response.getReason());
       } else {
-        logSevere(
-            "Create collection failed\n{0}\n{1}",
+        logError(
+            "Create collection failed\n{}\n{}",
             collectionMapping.toString(), response.toString());
         return new Response(
             Response.Status.valueOf(response.getErrorCodeValue()), response.getReason());
       }
     } catch (StatusRuntimeException e) {
-      logSevere("createCollection RPC failed:\n{0}", e.getStatus().toString());
+      logError("createCollection RPC failed:\n{}", e.getStatus().toString());
       return new Response(Response.Status.RPC_ERROR, e.toString());
     }
   }
@@ -209,11 +196,11 @@ public class MilvusGrpcClient implements MilvusClient {
       response = blockingStub.hasCollection(request);
 
       if (response.getStatus().getErrorCode() == ErrorCode.SUCCESS) {
-        logInfo("hasCollection `{0}` = {1}", collectionName, response.getBoolReply());
+        logInfo("hasCollection `{}` = {}", collectionName, response.getBoolReply());
         return new HasCollectionResponse(
             new Response(Response.Status.SUCCESS), response.getBoolReply());
       } else {
-        logSevere("hasCollection `{0}` failed:\n{1}", collectionName, response.toString());
+        logError("hasCollection `{}` failed:\n{}", collectionName, response.toString());
         return new HasCollectionResponse(
             new Response(
                 Response.Status.valueOf(response.getStatus().getErrorCodeValue()),
@@ -221,7 +208,7 @@ public class MilvusGrpcClient implements MilvusClient {
             false);
       }
     } catch (StatusRuntimeException e) {
-      logSevere("hasCollection RPC failed:\n{0}", e.getStatus().toString());
+      logError("hasCollection RPC failed:\n{}", e.getStatus().toString());
       return new HasCollectionResponse(
           new Response(Response.Status.RPC_ERROR, e.toString()), false);
     }
@@ -242,15 +229,15 @@ public class MilvusGrpcClient implements MilvusClient {
       response = blockingStub.dropCollection(request);
 
       if (response.getErrorCode() == ErrorCode.SUCCESS) {
-        logInfo("Dropped collection `{0}` successfully!", collectionName);
+        logInfo("Dropped collection `{}` successfully!", collectionName);
         return new Response(Response.Status.SUCCESS);
       } else {
-        logSevere("Drop collection `{0}` failed:\n{1}", collectionName, response.toString());
+        logError("Drop collection `{}` failed:\n{}", collectionName, response.toString());
         return new Response(
             Response.Status.valueOf(response.getErrorCodeValue()), response.getReason());
       }
     } catch (StatusRuntimeException e) {
-      logSevere("dropCollection RPC failed:\n{0}", e.getStatus().toString());
+      logError("dropCollection RPC failed:\n{}", e.getStatus().toString());
       return new Response(Response.Status.RPC_ERROR, e.toString());
     }
   }
@@ -278,15 +265,15 @@ public class MilvusGrpcClient implements MilvusClient {
       response = blockingStub.createIndex(request);
 
       if (response.getErrorCode() == ErrorCode.SUCCESS) {
-        logInfo("Created index successfully!\n{0}", index.toString());
+        logInfo("Created index successfully!\n{}", index.toString());
         return new Response(Response.Status.SUCCESS);
       } else {
-        logSevere("Create index failed:\n{0}\n{1}", index.toString(), response.toString());
+        logError("Create index failed:\n{}\n{}", index.toString(), response.toString());
         return new Response(
             Response.Status.valueOf(response.getErrorCodeValue()), response.getReason());
       }
     } catch (StatusRuntimeException e) {
-      logSevere("createIndex RPC failed:\n{0}", e.getStatus().toString());
+      logError("createIndex RPC failed:\n{}", e.getStatus().toString());
       return new Response(Response.Status.RPC_ERROR, e.toString());
     }
   }
@@ -318,15 +305,15 @@ public class MilvusGrpcClient implements MilvusClient {
           @Override
           public void onSuccess(Status result) {
             if (result.getErrorCode() == ErrorCode.SUCCESS) {
-              logInfo("Created index successfully!\n{0}", index.toString());
+              logInfo("Created index successfully!\n{}", index.toString());
             } else {
-              logSevere("CreateIndexAsync failed:\n{0}\n{1}", index.toString(), result.toString());
+              logError("CreateIndexAsync failed:\n{}\n{}", index.toString(), result.toString());
             }
           }
 
           @Override
           public void onFailure(Throwable t) {
-            logSevere("CreateIndexAsync failed:\n{0}", t.getMessage());
+            logError("CreateIndexAsync failed:\n{}", t.getMessage());
           }
         },
         MoreExecutors.directExecutor());
@@ -352,17 +339,17 @@ public class MilvusGrpcClient implements MilvusClient {
       response = blockingStub.createPartition(request);
 
       if (response.getErrorCode() == ErrorCode.SUCCESS) {
-        logInfo("Created partition `{0}` in collection `{1}` successfully!", tag, collectionName);
+        logInfo("Created partition `{}` in collection `{}` successfully!", tag, collectionName);
         return new Response(Response.Status.SUCCESS);
       } else {
-        logSevere(
-            "Create partition `{0}` in collection `{1}` failed: {2}",
+        logError(
+            "Create partition `{}` in collection `{}` failed: {}",
             tag, collectionName, response.toString());
         return new Response(
             Response.Status.valueOf(response.getErrorCodeValue()), response.getReason());
       }
     } catch (StatusRuntimeException e) {
-      logSevere("createPartition RPC failed:\n{0}", e.getStatus().toString());
+      logError("createPartition RPC failed:\n{}", e.getStatus().toString());
       return new Response(Response.Status.RPC_ERROR, e.toString());
     }
   }
@@ -383,11 +370,11 @@ public class MilvusGrpcClient implements MilvusClient {
       response = blockingStub.hasPartition(request);
 
       if (response.getStatus().getErrorCode() == ErrorCode.SUCCESS) {
-        logInfo("hasPartition with tag `{0}` in `{1}` = {2}", tag, collectionName, response.getBoolReply());
+        logInfo("hasPartition with tag `{}` in `{}` = {}", tag, collectionName, response.getBoolReply());
         return new HasPartitionResponse(
                 new Response(Response.Status.SUCCESS), response.getBoolReply());
       } else {
-        logSevere("hasPartition with tag `{0}` in `{1}` failed:\n{2}", tag, collectionName, response.toString());
+        logError("hasPartition with tag `{}` in `{}` failed:\n{}", tag, collectionName, response.toString());
         return new HasPartitionResponse(
                 new Response(
                         Response.Status.valueOf(response.getStatus().getErrorCodeValue()),
@@ -395,7 +382,7 @@ public class MilvusGrpcClient implements MilvusClient {
                 false);
       }
     } catch (StatusRuntimeException e) {
-      logSevere("hasPartition RPC failed:\n{0}", e.getStatus().toString());
+      logError("hasPartition RPC failed:\n{}", e.getStatus().toString());
       return new HasPartitionResponse(
               new Response(Response.Status.RPC_ERROR, e.toString()), false);
     }
@@ -418,12 +405,12 @@ public class MilvusGrpcClient implements MilvusClient {
 
       if (response.getStatus().getErrorCode() == ErrorCode.SUCCESS) {
         logInfo(
-            "Current partitions of collection {0}: {1}",
+            "Current partitions of collection {}: {}",
             collectionName, response.getPartitionTagArrayList());
         return new ShowPartitionsResponse(
             new Response(Response.Status.SUCCESS), response.getPartitionTagArrayList());
       } else {
-        logSevere("Show partitions failed:\n{0}", response.toString());
+        logError("Show partitions failed:\n{}", response.toString());
         return new ShowPartitionsResponse(
             new Response(
                 Response.Status.valueOf(response.getStatus().getErrorCodeValue()),
@@ -431,7 +418,7 @@ public class MilvusGrpcClient implements MilvusClient {
             new ArrayList<>());
       }
     } catch (StatusRuntimeException e) {
-      logSevere("showPartitions RPC failed:\n{0}", e.getStatus().toString());
+      logError("showPartitions RPC failed:\n{}", e.getStatus().toString());
       return new ShowPartitionsResponse(
           new Response(Response.Status.RPC_ERROR, e.toString()), new ArrayList<>());
     }
@@ -453,17 +440,17 @@ public class MilvusGrpcClient implements MilvusClient {
       response = blockingStub.dropPartition(request);
 
       if (response.getErrorCode() == ErrorCode.SUCCESS) {
-        logInfo("Dropped partition `{1}` in collection `{1}` successfully!", tag, collectionName);
+        logInfo("Dropped partition `{}` in collection `{}` successfully!", tag, collectionName);
         return new Response(Response.Status.SUCCESS);
       } else {
-        logSevere(
-            "Drop partition `{0}` in collection `{1}` failed:\n{1}",
+        logError(
+            "Drop partition `{}` in collection `{}` failed:\n{}",
             tag, collectionName, response.toString());
         return new Response(
             Response.Status.valueOf(response.getErrorCodeValue()), response.getReason());
       }
     } catch (StatusRuntimeException e) {
-      logSevere("dropPartition RPC failed:\n{0}", e.getStatus().toString());
+      logError("dropPartition RPC failed:\n{}", e.getStatus().toString());
       return new Response(Response.Status.RPC_ERROR, e.toString());
     }
   }
@@ -494,12 +481,12 @@ public class MilvusGrpcClient implements MilvusClient {
 
       if (response.getStatus().getErrorCode() == ErrorCode.SUCCESS) {
         logInfo(
-            "Inserted {0} vectors to collection `{1}` successfully!",
+            "Inserted {} vectors to collection `{}` successfully!",
             response.getVectorIdArrayCount(), insertParam.getCollectionName());
         return new InsertResponse(
             new Response(Response.Status.SUCCESS), response.getVectorIdArrayList());
       } else {
-        logSevere("Insert vectors failed:\n{0}", response.getStatus().toString());
+        logError("Insert vectors failed:\n{}", response.getStatus().toString());
         return new InsertResponse(
             new Response(
                 Response.Status.valueOf(response.getStatus().getErrorCodeValue()),
@@ -507,7 +494,7 @@ public class MilvusGrpcClient implements MilvusClient {
             new ArrayList<>());
       }
     } catch (StatusRuntimeException e) {
-      logSevere("insert RPC failed:\n{0}", e.getStatus().toString());
+      logError("insert RPC failed:\n{}", e.getStatus().toString());
       return new InsertResponse(
           new Response(Response.Status.RPC_ERROR, e.toString()), new ArrayList<>());
     }
@@ -545,16 +532,16 @@ public class MilvusGrpcClient implements MilvusClient {
           public void onSuccess(VectorIds result) {
             if (result.getStatus().getErrorCode() == ErrorCode.SUCCESS) {
               logInfo(
-                  "Inserted {0} vectors to collection `{1}` successfully!",
+                  "Inserted {} vectors to collection `{}` successfully!",
                   result.getVectorIdArrayCount(), insertParam.getCollectionName());
             } else {
-              logSevere("InsertAsync failed:\n{0}", result.getStatus().toString());
+              logError("InsertAsync failed:\n{}", result.getStatus().toString());
             }
           }
 
           @Override
           public void onFailure(Throwable t) {
-            logSevere("InsertAsync failed:\n{0}", t.getMessage());
+            logError("InsertAsync failed:\n{}", t.getMessage());
           }
         },
         MoreExecutors.directExecutor());
@@ -613,11 +600,11 @@ public class MilvusGrpcClient implements MilvusClient {
         SearchResponse searchResponse = buildSearchResponse(response);
         searchResponse.setResponse(new Response(Response.Status.SUCCESS));
         logInfo(
-            "Search completed successfully! Returned results for {0} queries",
+            "Search completed successfully! Returned results for {} queries",
             searchResponse.getNumQueries());
         return searchResponse;
       } else {
-        logSevere("Search failed:\n{0}", response.getStatus().toString());
+        logError("Search failed:\n{}", response.getStatus().toString());
         SearchResponse searchResponse = new SearchResponse();
         searchResponse.setResponse(
             new Response(
@@ -626,7 +613,7 @@ public class MilvusGrpcClient implements MilvusClient {
         return searchResponse;
       }
     } catch (StatusRuntimeException e) {
-      logSevere("search RPC failed:\n{0}", e.getStatus().toString());
+      logError("search RPC failed:\n{}", e.getStatus().toString());
       SearchResponse searchResponse = new SearchResponse();
       searchResponse.setResponse(new Response(Response.Status.RPC_ERROR, e.toString()));
       return searchResponse;
@@ -669,11 +656,11 @@ public class MilvusGrpcClient implements MilvusClient {
         SearchResponse searchResponse = buildSearchResponse(response);
         searchResponse.setResponse(new Response(Response.Status.SUCCESS));
         logInfo(
-                "Search by ids completed successfully! Returned results for {0} queries",
+                "Search by ids completed successfully! Returned results for {} queries",
                 searchResponse.getNumQueries());
         return searchResponse;
       } else {
-        logSevere("Search by ids failed:\n{0}", response.getStatus().toString());
+        logError("Search by ids failed:\n{}", response.getStatus().toString());
         SearchResponse searchResponse = new SearchResponse();
         searchResponse.setResponse(
                 new Response(
@@ -682,7 +669,7 @@ public class MilvusGrpcClient implements MilvusClient {
         return searchResponse;
       }
     } catch (StatusRuntimeException e) {
-      logSevere("search by ids RPC failed:\n{0}", e.getStatus().toString());
+      logError("search by ids RPC failed:\n{}", e.getStatus().toString());
       SearchResponse searchResponse = new SearchResponse();
       searchResponse.setResponse(new Response(Response.Status.RPC_ERROR, e.toString()));
       return searchResponse;
@@ -728,16 +715,16 @@ public class MilvusGrpcClient implements MilvusClient {
           public void onSuccess(TopKQueryResult result) {
             if (result.getStatus().getErrorCode() == ErrorCode.SUCCESS) {
               logInfo(
-                  "SearchAsync completed successfully! Returned results for {0} queries",
+                  "SearchAsync completed successfully! Returned results for {} queries",
                   result.getRowNum());
             } else {
-              logSevere("SearchAsync failed:\n{0}", result.getStatus().toString());
+              logError("SearchAsync failed:\n{}", result.getStatus().toString());
             }
           }
 
           @Override
           public void onFailure(Throwable t) {
-            logSevere("SearchAsync failed:\n{0}", t.getMessage());
+            logError("SearchAsync failed:\n{}", t.getMessage());
           }
         },
         MoreExecutors.directExecutor());
@@ -805,11 +792,11 @@ public class MilvusGrpcClient implements MilvusClient {
         SearchResponse searchResponse = buildSearchResponse(response);
         searchResponse.setResponse(new Response(Response.Status.SUCCESS));
         logInfo(
-            "Search in files completed successfully! Returned results for {0} queries",
+            "Search in files completed successfully! Returned results for {} queries",
             searchResponse.getNumQueries());
         return searchResponse;
       } else {
-        logSevere("Search in files failed: {0}", response.getStatus().toString());
+        logError("Search in files failed: {}", response.getStatus().toString());
 
         SearchResponse searchResponse = new SearchResponse();
         searchResponse.setResponse(
@@ -819,7 +806,7 @@ public class MilvusGrpcClient implements MilvusClient {
         return searchResponse;
       }
     } catch (StatusRuntimeException e) {
-      logSevere("searchInFiles RPC failed:\n{0}", e.getStatus().toString());
+      logError("searchInFiles RPC failed:\n{}", e.getStatus().toString());
       SearchResponse searchResponse = new SearchResponse();
       searchResponse.setResponse(new Response(Response.Status.RPC_ERROR, e.toString()));
       return searchResponse;
@@ -847,12 +834,12 @@ public class MilvusGrpcClient implements MilvusClient {
                 .withIndexFileSize(response.getIndexFileSize())
                 .withMetricType(MetricType.valueOf(response.getMetricType()))
                 .build();
-        logInfo("Describe Collection `{0}` returned:\n{1}", collectionName, collectionMapping);
+        logInfo("Describe Collection `{}` returned:\n{}", collectionName, collectionMapping);
         return new DescribeCollectionResponse(
             new Response(Response.Status.SUCCESS), collectionMapping);
       } else {
-        logSevere(
-            "Describe Collection `{0}` failed:\n{1}",
+        logError(
+            "Describe Collection `{}` failed:\n{}",
             collectionName, response.getStatus().toString());
         return new DescribeCollectionResponse(
             new Response(
@@ -861,7 +848,7 @@ public class MilvusGrpcClient implements MilvusClient {
             null);
       }
     } catch (StatusRuntimeException e) {
-      logSevere("describeCollection RPC failed:\n{0}", e.getStatus().toString());
+      logError("describeCollection RPC failed:\n{}", e.getStatus().toString());
       return new DescribeCollectionResponse(
           new Response(Response.Status.RPC_ERROR, e.toString()), null);
     }
@@ -884,10 +871,10 @@ public class MilvusGrpcClient implements MilvusClient {
 
       if (response.getStatus().getErrorCode() == ErrorCode.SUCCESS) {
         List<String> collectionNames = response.getCollectionNamesList();
-        logInfo("Current collections: {0}", collectionNames.toString());
+        logInfo("Current collections: {}", collectionNames.toString());
         return new ShowCollectionsResponse(new Response(Response.Status.SUCCESS), collectionNames);
       } else {
-        logSevere("Show collections failed:\n{0}", response.getStatus().toString());
+        logError("Show collections failed:\n{}", response.getStatus().toString());
         return new ShowCollectionsResponse(
             new Response(
                 Response.Status.valueOf(response.getStatus().getErrorCodeValue()),
@@ -895,7 +882,7 @@ public class MilvusGrpcClient implements MilvusClient {
             new ArrayList<>());
       }
     } catch (StatusRuntimeException e) {
-      logSevere("showCollections RPC failed:\n{0}", e.getStatus().toString());
+      logError("showCollections RPC failed:\n{}", e.getStatus().toString());
       return new ShowCollectionsResponse(
           new Response(Response.Status.RPC_ERROR, e.toString()), new ArrayList<>());
     }
@@ -918,12 +905,12 @@ public class MilvusGrpcClient implements MilvusClient {
 
       if (response.getStatus().getErrorCode() == ErrorCode.SUCCESS) {
         long collectionRowCount = response.getCollectionRowCount();
-        logInfo("Collection `{0}` has {1} rows", collectionName, collectionRowCount);
+        logInfo("Collection `{}` has {} rows", collectionName, collectionRowCount);
         return new GetCollectionRowCountResponse(
             new Response(Response.Status.SUCCESS), collectionRowCount);
       } else {
-        logSevere(
-            "Get collection `{0}` row count failed:\n{1}",
+        logError(
+            "Get collection `{}` row count failed:\n{}",
             collectionName, response.getStatus().toString());
         return new GetCollectionRowCountResponse(
             new Response(
@@ -932,7 +919,7 @@ public class MilvusGrpcClient implements MilvusClient {
             0);
       }
     } catch (StatusRuntimeException e) {
-      logSevere("countCollection RPC failed:\n{0}", e.getStatus().toString());
+      logError("countCollection RPC failed:\n{}", e.getStatus().toString());
       return new GetCollectionRowCountResponse(
           new Response(Response.Status.RPC_ERROR, e.toString()), 0);
     }
@@ -962,16 +949,16 @@ public class MilvusGrpcClient implements MilvusClient {
       response = blockingStub.cmd(request);
 
       if (response.getStatus().getErrorCode() == ErrorCode.SUCCESS) {
-        logInfo("Command `{0}`: {1}", command, response.getStringReply());
+        logInfo("Command `{}`: {}", command, response.getStringReply());
         return new Response(Response.Status.SUCCESS, response.getStringReply());
       } else {
-        logSevere("Command `{0}` failed:\n{1}", command, response.toString());
+        logError("Command `{}` failed:\n{}", command, response.toString());
         return new Response(
             Response.Status.valueOf(response.getStatus().getErrorCodeValue()),
             response.getStatus().getReason());
       }
     } catch (StatusRuntimeException e) {
-      logSevere("Command RPC failed:\n{0}", e.getStatus().toString());
+      logError("Command RPC failed:\n{}", e.getStatus().toString());
       return new Response(Response.Status.RPC_ERROR, e.toString());
     }
   }
@@ -991,15 +978,15 @@ public class MilvusGrpcClient implements MilvusClient {
       response = blockingStub.preloadCollection(request);
 
       if (response.getErrorCode() == ErrorCode.SUCCESS) {
-        logInfo("Preloaded collection `{0}` successfully!", collectionName);
+        logInfo("Preloaded collection `{}` successfully!", collectionName);
         return new Response(Response.Status.SUCCESS);
       } else {
-        logSevere("Preload collection `{0}` failed:\n{1}", collectionName, response.toString());
+        logError("Preload collection `{}` failed:\n{}", collectionName, response.toString());
         return new Response(
             Response.Status.valueOf(response.getErrorCodeValue()), response.getReason());
       }
     } catch (StatusRuntimeException e) {
-      logSevere("preloadCollection RPC failed:\n{0}", e.getStatus().toString());
+      logError("preloadCollection RPC failed:\n{}", e.getStatus().toString());
       return new Response(Response.Status.RPC_ERROR, e.toString());
     }
   }
@@ -1030,11 +1017,11 @@ public class MilvusGrpcClient implements MilvusClient {
                 .withParamsInJson(extraParam)
                 .build();
         logInfo(
-            "Describe index for collection `{0}` returned:\n{1}", collectionName, index.toString());
+            "Describe index for collection `{}` returned:\n{}", collectionName, index.toString());
         return new DescribeIndexResponse(new Response(Response.Status.SUCCESS), index);
       } else {
-        logSevere(
-            "Describe index for collection `{0}` failed:\n{1}",
+        logError(
+            "Describe index for collection `{}` failed:\n{}",
             collectionName, response.getStatus().toString());
         return new DescribeIndexResponse(
             new Response(
@@ -1043,7 +1030,7 @@ public class MilvusGrpcClient implements MilvusClient {
             null);
       }
     } catch (StatusRuntimeException e) {
-      logSevere("describeIndex RPC failed:\n{0}", e.getStatus().toString());
+      logError("describeIndex RPC failed:\n{}", e.getStatus().toString());
       return new DescribeIndexResponse(new Response(Response.Status.RPC_ERROR, e.toString()), null);
     }
   }
@@ -1063,16 +1050,16 @@ public class MilvusGrpcClient implements MilvusClient {
       response = blockingStub.dropIndex(request);
 
       if (response.getErrorCode() == ErrorCode.SUCCESS) {
-        logInfo("Dropped index for collection `{0}` successfully!", collectionName);
+        logInfo("Dropped index for collection `{}` successfully!", collectionName);
         return new Response(Response.Status.SUCCESS);
       } else {
-        logSevere(
-            "Drop index for collection `{0}` failed:\n{1}", collectionName, response.toString());
+        logError(
+            "Drop index for collection `{}` failed:\n{}", collectionName, response.toString());
         return new Response(
             Response.Status.valueOf(response.getErrorCodeValue()), response.getReason());
       }
     } catch (StatusRuntimeException e) {
-      logSevere("dropIndex RPC failed:\n{0}", e.getStatus().toString());
+      logError("dropIndex RPC failed:\n{}", e.getStatus().toString());
       return new Response(Response.Status.RPC_ERROR, e.toString());
     }
   }
@@ -1091,18 +1078,18 @@ public class MilvusGrpcClient implements MilvusClient {
       response = blockingStub.showCollectionInfo(request);
 
       if (response.getStatus().getErrorCode() == ErrorCode.SUCCESS) {
-        logInfo("ShowCollectionInfo for `{0}` returned successfully!", collectionName);
+        logInfo("ShowCollectionInfo for `{}` returned successfully!", collectionName);
         return new Response(Response.Status.SUCCESS, response.getJsonInfo());
       } else {
-        logSevere(
-            "ShowCollectionInfo for `{0}` failed:\n{1}",
+        logError(
+            "ShowCollectionInfo for `{}` failed:\n{}",
             collectionName, response.getStatus().toString());
         return new Response(
                 Response.Status.valueOf(response.getStatus().getErrorCodeValue()),
                 response.getStatus().getReason());
       }
     } catch (StatusRuntimeException e) {
-      logSevere("showCollectionInfo RPC failed:\n{0}", e.getStatus().toString());
+      logError("showCollectionInfo RPC failed:\n{}", e.getStatus().toString());
       return new Response(Response.Status.RPC_ERROR, e.toString());
     }
   }
@@ -1125,7 +1112,7 @@ public class MilvusGrpcClient implements MilvusClient {
       if (response.getStatus().getErrorCode() == ErrorCode.SUCCESS) {
 
         logInfo(
-            "getVectorsByIds in collection `{0}` returned successfully!", collectionName);
+            "getVectorsByIds in collection `{}` returned successfully!", collectionName);
 
         List<List<Float>> floatVectors = new ArrayList<>();
         List<ByteBuffer> binaryVectors = new ArrayList<>();
@@ -1137,8 +1124,8 @@ public class MilvusGrpcClient implements MilvusClient {
                 new Response(Response.Status.SUCCESS), floatVectors, binaryVectors);
 
       } else {
-        logSevere(
-            "getVectorsByIds in collection `{0}` failed:\n{1}",
+        logError(
+            "getVectorsByIds in collection `{}` failed:\n{}",
             collectionName, response.getStatus().toString());
         return new GetVectorsByIdsResponse(
             new Response(
@@ -1148,7 +1135,7 @@ public class MilvusGrpcClient implements MilvusClient {
             null);
       }
     } catch (StatusRuntimeException e) {
-      logSevere("getVectorsByIds RPC failed:\n{0}", e.getStatus().toString());
+      logError("getVectorsByIds RPC failed:\n{}", e.getStatus().toString());
       return new GetVectorsByIdsResponse(
           new Response(Response.Status.RPC_ERROR, e.toString()), new ArrayList<>(), null);
     }
@@ -1175,13 +1162,13 @@ public class MilvusGrpcClient implements MilvusClient {
       if (response.getStatus().getErrorCode() == ErrorCode.SUCCESS) {
 
         logInfo(
-            "getVectorIds in collection `{0}`, segment `{1}` returned successfully!",
+            "getVectorIds in collection `{}`, segment `{}` returned successfully!",
             collectionName, segmentName);
         return new GetVectorIdsResponse(
             new Response(Response.Status.SUCCESS), response.getVectorIdArrayList());
       } else {
-        logSevere(
-            "getVectorIds in collection `{0}`, segment `{1}` failed:\n{2}",
+        logError(
+            "getVectorIds in collection `{}`, segment `{}` failed:\n{}",
             collectionName, segmentName, response.getStatus().toString());
         return new GetVectorIdsResponse(
             new Response(
@@ -1190,7 +1177,7 @@ public class MilvusGrpcClient implements MilvusClient {
             new ArrayList<>());
       }
     } catch (StatusRuntimeException e) {
-      logSevere("getVectorIds RPC failed:\n{0}", e.getStatus().toString());
+      logError("getVectorIds RPC failed:\n{}", e.getStatus().toString());
       return new GetVectorIdsResponse(
           new Response(Response.Status.RPC_ERROR, e.toString()), new ArrayList<>());
     }
@@ -1211,16 +1198,16 @@ public class MilvusGrpcClient implements MilvusClient {
       response = blockingStub.deleteByID(request);
 
       if (response.getErrorCode() == ErrorCode.SUCCESS) {
-        logInfo("deleteByIds in collection `{0}` completed successfully!", collectionName);
+        logInfo("deleteByIds in collection `{}` completed successfully!", collectionName);
         return new Response(Response.Status.SUCCESS);
       } else {
-        logSevere(
-            "deleteByIds in collection `{0}` failed:\n{1}", collectionName, response.toString());
+        logError(
+            "deleteByIds in collection `{}` failed:\n{}", collectionName, response.toString());
         return new Response(
             Response.Status.valueOf(response.getErrorCodeValue()), response.getReason());
       }
     } catch (StatusRuntimeException e) {
-      logSevere("deleteByIds RPC failed:\n{0}", e.getStatus().toString());
+      logError("deleteByIds RPC failed:\n{}", e.getStatus().toString());
       return new Response(Response.Status.RPC_ERROR, e.toString());
     }
   }
@@ -1250,15 +1237,15 @@ public class MilvusGrpcClient implements MilvusClient {
       response = blockingStub.flush(request);
 
       if (response.getErrorCode() == ErrorCode.SUCCESS) {
-        logInfo("Flushed collection {0} successfully!", collectionNames);
+        logInfo("Flushed collection {} successfully!", collectionNames);
         return new Response(Response.Status.SUCCESS);
       } else {
-        logSevere("Flush collection {0} failed:\n{1}", collectionNames, response.toString());
+        logError("Flush collection {} failed:\n{}", collectionNames, response.toString());
         return new Response(
             Response.Status.valueOf(response.getErrorCodeValue()), response.getReason());
       }
     } catch (StatusRuntimeException e) {
-      logSevere("flush RPC failed:\n{0}", e.getStatus().toString());
+      logError("flush RPC failed:\n{}", e.getStatus().toString());
       return new Response(Response.Status.RPC_ERROR, e.toString());
     }
   }
@@ -1283,15 +1270,15 @@ public class MilvusGrpcClient implements MilvusClient {
           @Override
           public void onSuccess(Status result) {
             if (result.getErrorCode() == ErrorCode.SUCCESS) {
-              logInfo("Flushed collection {0} successfully!", collectionNames);
+              logInfo("Flushed collection {} successfully!", collectionNames);
             } else {
-              logSevere("Flush collection {0} failed:\n{1}", collectionNames, result.toString());
+              logError("Flush collection {} failed:\n{}", collectionNames, result.toString());
             }
           }
 
           @Override
           public void onFailure(Throwable t) {
-            logSevere("FlushAsync failed:\n{0}", t.getMessage());
+            logError("FlushAsync failed:\n{}", t.getMessage());
           }
         },
         MoreExecutors.directExecutor());
@@ -1336,15 +1323,15 @@ public class MilvusGrpcClient implements MilvusClient {
       response = blockingStub.compact(request);
 
       if (response.getErrorCode() == ErrorCode.SUCCESS) {
-        logInfo("Compacted collection `{0}` successfully!", collectionName);
+        logInfo("Compacted collection `{}` successfully!", collectionName);
         return new Response(Response.Status.SUCCESS);
       } else {
-        logSevere("Compact collection `{0}` failed:\n{1}", collectionName, response.toString());
+        logError("Compact collection `{}` failed:\n{}", collectionName, response.toString());
         return new Response(
             Response.Status.valueOf(response.getErrorCodeValue()), response.getReason());
       }
     } catch (StatusRuntimeException e) {
-      logSevere("compact RPC failed:\n{0}", e.getStatus().toString());
+      logError("compact RPC failed:\n{}", e.getStatus().toString());
       return new Response(Response.Status.RPC_ERROR, e.toString());
     }
   }
@@ -1369,15 +1356,15 @@ public class MilvusGrpcClient implements MilvusClient {
           @Override
           public void onSuccess(Status result) {
             if (result.getErrorCode() == ErrorCode.SUCCESS) {
-              logInfo("Compacted collection `{0}` successfully!", collectionName);
+              logInfo("Compacted collection `{}` successfully!", collectionName);
             } else {
-              logSevere("Compact collection `{0}` failed:\n{1}", collectionName, result.toString());
+              logError("Compact collection `{}` failed:\n{}", collectionName, result.toString());
             }
           }
 
           @Override
           public void onFailure(Throwable t) {
-            logSevere("CompactAsync failed:\n{0}", t.getMessage());
+            logError("CompactAsync failed:\n{}", t.getMessage());
           }
         },
         MoreExecutors.directExecutor());
@@ -1467,14 +1454,14 @@ public class MilvusGrpcClient implements MilvusClient {
   ///////////////////// Log Functions//////////////////////
 
   private void logInfo(String msg, Object... params) {
-    logger.log(Level.INFO, ANSI_YELLOW + msg + ANSI_RESET, params);
+    logger.info(msg, params);
   }
 
   private void logWarning(String msg, Object... params) {
-    logger.log(Level.WARNING, ANSI_PURPLE + msg + ANSI_RESET, params);
+    logger.warn(msg, params);
   }
 
-  private void logSevere(String msg, Object... params) {
-    logger.log(Level.SEVERE, ANSI_BRIGHT_PURPLE + msg + ANSI_RESET, params);
+  private void logError(String msg, Object... params) {
+    logger.error(msg, params);
   }
 }

+ 13 - 0
src/main/resources/log4j2.xml

@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Configuration status="INFO">
+    <Appenders>
+        <Console name="Console" target="SYSTEM_OUT">
+            <PatternLayout pattern="%highlight{%d{yyyy-MM-dd HH:mm:ss} %C %M %n%p: %m%n}{STYLE=Logback}"/>
+        </Console>
+    </Appenders>
+    <Loggers>
+        <Root level="INFO">
+            <AppenderRef ref="Console"/>
+        </Root>
+    </Loggers>
+</Configuration>

+ 5 - 5
src/test/java/io/milvus/client/MilvusGrpcClientTest.java

@@ -289,7 +289,7 @@ class MilvusClientTest {
 
     Index index =
         new Index.Builder(randomCollectionName, IndexType.IVF_SQ8)
-            .withParamsInJson("{\"nlist\": 19384}")
+            .withParamsInJson("{\"nlist\": 16384}")
             .build();
 
     Response createIndexResponse = client.createIndex(index);
@@ -303,7 +303,7 @@ class MilvusClientTest {
 
     Index index =
         new Index.Builder(randomCollectionName, IndexType.IVF_SQ8)
-            .withParamsInJson("{\"nlist\": 19384}")
+            .withParamsInJson("{\"nlist\": 16384}")
             .build();
 
     ListenableFuture<Response> createIndexResponseFuture = client.createIndexAsync(index);
@@ -744,7 +744,7 @@ class MilvusClientTest {
 
     long previousSegmentSize = segmentInfo.getLong("data_size");
 
-    assertTrue(client.deleteByIds(randomCollectionName, vectorIds.subList(0, 100)).ok());
+    assertTrue(client.deleteByIds(randomCollectionName, vectorIds.subList(0, (int) size / 2)).ok());
     assertTrue(client.flush(randomCollectionName).ok());
     assertTrue(client.compact(randomCollectionName).ok());
 
@@ -756,8 +756,8 @@ class MilvusClientTest {
             .getJSONObject(0)
             .getJSONArray("segments")
             .getJSONObject(0);
-    long currentSegmentSize = segmentInfo.getLong("data_size");
 
+    long currentSegmentSize = segmentInfo.getLong("data_size");
     assertTrue(currentSegmentSize < previousSegmentSize);
   }
 
@@ -786,7 +786,7 @@ class MilvusClientTest {
 
     long previousSegmentSize = segmentInfo.getLong("data_size");
 
-    assertTrue(client.deleteByIds(randomCollectionName, vectorIds.subList(0, 100)).ok());
+    assertTrue(client.deleteByIds(randomCollectionName, vectorIds.subList(0, (int) size / 2)).ok());
     assertTrue(client.flush(randomCollectionName).ok());
     assertTrue(client.compactAsync(randomCollectionName).get().ok());