Skip to content

Commit

Permalink
HSEARCH-798 Make logging report reproducible
Browse files Browse the repository at this point in the history
i.e. fields printed in the same order all the time
  • Loading branch information
marko-bekhta committed Nov 27, 2024
1 parent 64ec558 commit ce5113a
Showing 1 changed file with 9 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
import java.io.Writer;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand Down Expand Up @@ -117,17 +119,12 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
writer.write( "# This Hibernate Search module does not use any logging categories.\n" );
}
else {
Map<String, Object> data = new LinkedHashMap<>();
data.put( ReportConstants.MODULE_NAME, moduleName );
data.put( ReportConstants.CATEGORIES, toYamlCategories( categories, categoryLevels ) );

Yaml yaml = new Yaml();
yaml.dump(
Map.of(
ReportConstants.ROOT,
Map.of(
ReportConstants.MODULE_NAME, moduleName,
ReportConstants.CATEGORIES, toYamlCategories( categories, categoryLevels )
)
),
writer
);
yaml.dump( Collections.singletonMap( ReportConstants.ROOT, data ), writer );
}
}
catch (IOException e) {
Expand All @@ -146,7 +143,7 @@ ReportConstants.CATEGORIES, toYamlCategories( categories, categoryLevels )
private List<Map<String, Object>> toYamlCategories(Map<String, String> categories, Map<String, Set<String>> levels) {
List<Map<String, Object>> values = new ArrayList<>();
for ( var entry : categories.entrySet() ) {
Map<String, Object> value = new HashMap<>();
Map<String, Object> value = new LinkedHashMap<>();
value.put( ReportConstants.CATEGORY_NAME, entry.getKey() );
value.put( ReportConstants.CATEGORY_DESCRIPTION, entry.getValue() );
value.put( ReportConstants.LOG_LEVELS, new ArrayList<>( levels.getOrDefault( entry.getKey(), Set.of() ) ) );
Expand Down

0 comments on commit ce5113a

Please sign in to comment.