19
19
import java .util .stream .Collectors ;
20
20
import java .util .stream .Stream ;
21
21
22
+ import org .apache .commons .logging .LogFactory ;
23
+ import org .neo4j .driver .NotificationCategory ;
22
24
import org .neo4j .driver .summary .InputPosition ;
23
25
import org .neo4j .driver .summary .Notification ;
24
26
import org .neo4j .driver .summary .Plan ;
25
27
import org .neo4j .driver .summary .ResultSummary ;
28
+ import org .springframework .core .log .LogAccessor ;
26
29
27
30
/**
28
31
* Utility class for dealing with result summaries.
34
37
final class ResultSummaries {
35
38
36
39
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" ));
37
46
38
47
/**
39
48
* Does some post-processing on the giving result summary, especially logging all notifications
@@ -57,15 +66,41 @@ private static void logNotifications(ResultSummary resultSummary) {
57
66
String query = resultSummary .query ().text ();
58
67
resultSummary .notifications ()
59
68
.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 ));
66
79
});
67
80
}
68
81
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
+
69
104
/**
70
105
* Creates a formatted string for a notification issued for a given query.
71
106
*
0 commit comments