1919import java .util .stream .Collectors ;
2020import java .util .stream .Stream ;
2121
22+ import org .apache .commons .logging .LogFactory ;
23+ import org .neo4j .driver .NotificationCategory ;
2224import org .neo4j .driver .summary .InputPosition ;
2325import org .neo4j .driver .summary .Notification ;
2426import org .neo4j .driver .summary .Plan ;
2527import org .neo4j .driver .summary .ResultSummary ;
28+ import org .springframework .core .log .LogAccessor ;
2629
2730/**
2831 * Utility class for dealing with result summaries.
3437final class ResultSummaries {
3538
3639 private static final String LINE_SEPARATOR = System .lineSeparator ();
40+ private static final LogAccessor cypherPerformanceNotificationLog = new LogAccessor (LogFactory .getLog ("org.springframework.data.neo4j.cypher.performance" ));
41+ private static final LogAccessor cypherHintNotificationLog = new LogAccessor (LogFactory .getLog ("org.springframework.data.neo4j.cypher.hint" ));
42+ private static final LogAccessor cypherUnrecognizedNotificationLog = new LogAccessor (LogFactory .getLog ("org.springframework.data.neo4j.cypher.unrecognized" ));
43+ private static final LogAccessor cypherUnsupportedNotificationLog = new LogAccessor (LogFactory .getLog ("org.springframework.data.neo4j.cypher.unsupported" ));
44+ private static final LogAccessor cypherDeprecationNotificationLog = new LogAccessor (LogFactory .getLog ("org.springframework.data.neo4j.cypher.deprecation" ));
45+ private static final LogAccessor cypherGenericNotificationLog = new LogAccessor (LogFactory .getLog ("org.springframework.data.neo4j.cypher.generic" ));
3746
3847 /**
3948 * Does some post-processing on the giving result summary, especially logging all notifications
@@ -57,15 +66,41 @@ private static void logNotifications(ResultSummary resultSummary) {
5766 String query = resultSummary .query ().text ();
5867 resultSummary .notifications ()
5968 .forEach (notification -> {
60- Consumer <String > log = switch (notification .severity ()) {
61- case "WARNING" -> Neo4jClient .cypherLog ::warn ;
62- case "INFORMATION" -> Neo4jClient .cypherLog ::info ;
63- default -> Neo4jClient .cypherLog ::debug ;
64- };
65- log .accept (ResultSummaries .format (notification , query ));
69+ LogAccessor log = notification .category ()
70+ .map (ResultSummaries ::getLogAccessor )
71+ .orElse (Neo4jClient .cypherLog );
72+ Consumer <String > logFunction =
73+ switch (notification .severity ()) {
74+ case "WARNING" -> log ::warn ;
75+ case "INFORMATION" -> log ::info ;
76+ default -> log ::debug ;
77+ };
78+ logFunction .accept (ResultSummaries .format (notification , query ));
6679 });
6780 }
6881
82+ private static LogAccessor getLogAccessor (NotificationCategory category ) {
83+ if (category == NotificationCategory .HINT ) {
84+ return cypherHintNotificationLog ;
85+ }
86+ if (category == NotificationCategory .DEPRECATION ) {
87+ return cypherDeprecationNotificationLog ;
88+ }
89+ if (category == NotificationCategory .PERFORMANCE ) {
90+ return cypherPerformanceNotificationLog ;
91+ }
92+ if (category == NotificationCategory .GENERIC ) {
93+ return cypherGenericNotificationLog ;
94+ }
95+ if (category == NotificationCategory .UNSUPPORTED ) {
96+ return cypherUnsupportedNotificationLog ;
97+ }
98+ if (category == NotificationCategory .UNRECOGNIZED ) {
99+ return cypherUnrecognizedNotificationLog ;
100+ }
101+ return Neo4jClient .cypherLog ;
102+ }
103+
69104 /**
70105 * Creates a formatted string for a notification issued for a given query.
71106 *
0 commit comments