2626import org .elasticsearch .index .codec .vectors .es818 .ES818BinaryQuantizedVectorsFormat ;
2727import org .elasticsearch .index .codec .vectors .es818 .ES818HnswBinaryQuantizedVectorsFormat ;
2828import org .elasticsearch .logging .Level ;
29+ import org .elasticsearch .logging .LogManager ;
30+ import org .elasticsearch .logging .Logger ;
2931import org .elasticsearch .xcontent .XContentParser ;
3032import org .elasticsearch .xcontent .XContentParserConfiguration ;
3133import org .elasticsearch .xcontent .XContentType ;
4446 * It supports various index types (HNSW, FLAT, IVF) and configurations.
4547 */
4648public class KnnIndexTester {
47- static final Level LOG_LEVEL = Level .DEBUG ;
48-
49- static final SysOutLogger logger = new SysOutLogger ();
49+ static final Logger logger ;
5050
5151 static {
5252 LogConfigurator .loadLog4jPlugins ();
@@ -57,6 +57,8 @@ public class KnnIndexTester {
5757 String loggerLevel = sysprops .getOrDefault ("es.logger.level" , Level .INFO .name ());
5858 Settings settings = Settings .builder ().put ("logger.level" , loggerLevel ).build ();
5959 LogConfigurator .configureWithoutConfig (settings );
60+
61+ logger = LogManager .getLogger (KnnIndexTester .class );
6062 }
6163
6264 static final String INDEX_DIR = "target/knn_index" ;
@@ -172,7 +174,7 @@ public static void main(String[] args) throws Exception {
172174 FormattedResults formattedResults = new FormattedResults ();
173175 for (CmdLineArgs cmdLineArgs : cmdLineArgsList ) {
174176 Results result = new Results (cmdLineArgs .indexType ().name ().toLowerCase (Locale .ROOT ), cmdLineArgs .numDocs ());
175- System . out . println ("Running KNN index tester with arguments: " + cmdLineArgs );
177+ logger . info ("Running KNN index tester with arguments: " + cmdLineArgs );
176178 Codec codec = createCodec (cmdLineArgs );
177179 Path indexPath = PathUtils .get (formatIndexPath (cmdLineArgs ));
178180 if (cmdLineArgs .reindex () || cmdLineArgs .forceMerge ()) {
@@ -204,8 +206,7 @@ public static void main(String[] args) throws Exception {
204206 }
205207 formattedResults .results .add (result );
206208 }
207- System .out .println ("Results:" );
208- System .out .println (formattedResults );
209+ logger .info ("Results: \n " + formattedResults );
209210 }
210211
211212 static class FormattedResults {
@@ -335,57 +336,6 @@ static class Results {
335336 }
336337 }
337338
338- static final class SysOutLogger {
339-
340- void warn (String message ) {
341- if (LOG_LEVEL .ordinal () >= Level .WARN .ordinal ()) {
342- System .out .println (message );
343- }
344- }
345-
346- void warn (String message , Object ... params ) {
347- if (LOG_LEVEL .ordinal () >= Level .WARN .ordinal ()) {
348- System .out .println (String .format (Locale .ROOT , message , params ));
349- }
350- }
351-
352- void info (String message ) {
353- if (LOG_LEVEL .ordinal () >= Level .INFO .ordinal ()) {
354- System .out .println (message );
355- }
356- }
357-
358- void info (String message , Object ... params ) {
359- if (LOG_LEVEL .ordinal () >= Level .INFO .ordinal ()) {
360- System .out .println (String .format (Locale .ROOT , message , params ));
361- }
362- }
363-
364- void debug (String message ) {
365- if (LOG_LEVEL .ordinal () >= Level .DEBUG .ordinal ()) {
366- System .out .println (message );
367- }
368- }
369-
370- void debug (String message , Object ... params ) {
371- if (LOG_LEVEL .ordinal () >= Level .DEBUG .ordinal ()) {
372- System .out .println (String .format (Locale .ROOT , message , params ));
373- }
374- }
375-
376- void trace (String message ) {
377- if (LOG_LEVEL == Level .TRACE ) {
378- System .out .println (message );
379- }
380- }
381-
382- void trace (String message , Object ... params ) {
383- if (LOG_LEVEL == Level .TRACE ) {
384- System .out .println (String .format (Locale .ROOT , message , params ));
385- }
386- }
387- }
388-
389339 static final class ThreadDetails {
390340 private static final ThreadMXBean threadBean = (ThreadMXBean ) java .lang .management .ManagementFactory .getThreadMXBean ();
391341 public final long [] threadIDs ;
0 commit comments