Skip to content

Commit f76b017

Browse files
committed
GH-2800 - Loggers for each Cypher category.
1 parent be2b50c commit f76b017

File tree

4 files changed

+111
-19
lines changed

4 files changed

+111
-19
lines changed
+39-9
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,46 @@
11
[[logging]]
22
= Logging
33

4-
Spring Data Neo4j defines two named logger to log Cypher statements and warnings.
4+
Spring Data Neo4j provides multiple loggers for https://neo4j.com/docs/status-codes/current/notifications/all-notifications/[Cypher notifications], starting with version 7.1.5.
5+
The logger `org.springframework.data.neo4j.cypher` includes all statements that were invoked by Spring Data Neo4j and all notifications sent from the server.
6+
To exclude or elevate some categories, the following loggers are in place:
57

6-
== Cypher statements and statement related warnings/errors
8+
* `org.springframework.data.neo4j.cypher.performance`
9+
+
10+
Includes `Neo.ClientNotification.Statement.CartesianProduct`,
11+
`Neo.ClientNotification.Statement.UnboundedVariableLengthPattern`,
12+
`Neo.ClientNotification.Statement.ExhaustiveShortestPath`,
13+
`Neo.ClientNotification.Statement.NoApplicableIndex`,
14+
`Neo.ClientNotification.Statement.EagerOperator`,
15+
`Neo.ClientNotification.Statement.DynamicProperty`,
16+
`Neo.ClientNotification.Statement.CodeGenerationFailed`
717

8-
`org.springframework.data.neo4j.cypher` includes all statements that were invoked by Spring Data Neo4j and warnings/errors sent from the server
18+
* `org.springframework.data.neo4j.cypher.hint`
19+
+
20+
Includes `Neo.ClientNotification.Statement.JoinHintUnfulfillableWarning`,
21+
`Neo.ClientNotification.Schema.HintedIndexNotFound`
922

10-
== Cypher notifications
23+
* `org.springframework.data.neo4j.cypher.unrecognized`
24+
+
25+
Includes `Neo.ClientNotification.Database.HomeDatabaseNotFound`,
26+
`Neo.ClientNotification.Statement.UnknownLabelWarning`,
27+
`Neo.ClientNotification.Statement.UnknownRelationshipTypeWarning`,
28+
`Neo.ClientNotification.Statement.UnknownPropertyKeyWarning`
1129

12-
`org.springframework.data.neo4j.cypher.notifications` is used to catch notifications regarding missing properties, labels and relationship types.
13-
Additionally, it also is responsible for the deprecation warnings, including usage of the deprecated `id()`.
14-
As we have experienced that those messages can be overwhelming when used in combination with Spring Data Neo4j, this logger catches all
15-
`Neo.ClientNotification.Statement.UnknownRelationshipTypeWarning`, `Neo.ClientNotification.Statement.UnknownLabelWarning`, `Neo.ClientNotification.Statement.UnknownPropertyKeyWarning`, `Neo.ClientNotification.Statement.FeatureDeprecationWarning`.
16-
If you rely purely on Spring Data Neo4j's generated statements or are confident with your custom Cypher statements, you can set this logger to `ERROR` level.
30+
* `org.springframework.data.neo4j.cypher.unsupported`
31+
+
32+
Includes `Neo.ClientNotification.Statement.RuntimeUnsupportedWarning`,
33+
`Neo.ClientNotification.Statement.RuntimeExperimental`
34+
35+
* `org.springframework.data.neo4j.cypher.deprecation`
36+
+
37+
Includes `Neo.ClientNotification.Statement.FeatureDeprecationWarning`,
38+
`Neo.ClientNotification.Request.DeprecatedFormat`
39+
40+
* `org.springframework.data.neo4j.cypher.generic`
41+
+
42+
Includes `Neo.ClientNotification.Statement.SubqueryVariableShadowing`,
43+
`Neo.ClientNotification.Statement.ParameterNotProvided`,
44+
`Neo.ClientNotification.Procedure.ProcedureWarning`,
45+
`Neo.ClientNotification.Statement.UnsatisfiableRelationshipTypeExpression`,
46+
`Neo.ClientNotification.Statement.RepeatedRelationshipReference`

src/main/java/org/springframework/data/neo4j/core/Neo4jClient.java

+40-5
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,49 @@
4646
public interface Neo4jClient {
4747

4848
LogAccessor cypherLog = new LogAccessor(LogFactory.getLog("org.springframework.data.neo4j.cypher"));
49-
LogAccessor cypherNotificationLog = new LogAccessor(LogFactory.getLog("org.springframework.data.neo4j.cypher.notifications"));
49+
LogAccessor cypherPerformanceNotificationLog = new LogAccessor(LogFactory.getLog("org.springframework.data.neo4j.cypher.performance"));
50+
LogAccessor cypherHintNotificationLog = new LogAccessor(LogFactory.getLog("org.springframework.data.neo4j.cypher.hint"));
51+
LogAccessor cypherUnrecognizedNotificationLog = new LogAccessor(LogFactory.getLog("org.springframework.data.neo4j.cypher.unrecognized"));
52+
LogAccessor cypherUnsupportedNotificationLog = new LogAccessor(LogFactory.getLog("org.springframework.data.neo4j.cypher.unsupported"));
53+
LogAccessor cypherDeprecationNotificationLog = new LogAccessor(LogFactory.getLog("org.springframework.data.neo4j.cypher.deprecation"));
54+
LogAccessor cypherGenericNotificationLog = new LogAccessor(LogFactory.getLog("org.springframework.data.neo4j.cypher.generic"));
5055
LogAccessor log = new LogAccessor(LogFactory.getLog(Neo4jClient.class));
5156

52-
Set<String> cypherNotificationCategories = Set.of(
53-
"Neo.ClientNotification.Statement.UnknownRelationshipTypeWarning",
57+
// from https://neo4j.com/docs/status-codes/current/notifications/all-notifications/
58+
Set<String> cypherPerformanceNotificationCodes = Set.of(
59+
"Neo.ClientNotification.Statement.CartesianProduct",
60+
"Neo.ClientNotification.Statement.UnboundedVariableLengthPattern",
61+
"Neo.ClientNotification.Statement.ExhaustiveShortestPath",
62+
"Neo.ClientNotification.Statement.NoApplicableIndex",
63+
"Neo.ClientNotification.Statement.EagerOperator",
64+
"Neo.ClientNotification.Statement.DynamicProperty",
65+
"Neo.ClientNotification.Statement.CodeGenerationFailed");
66+
67+
Set<String> cypherHintNotificationCodes = Set.of(
68+
"Neo.ClientNotification.Statement.JoinHintUnfulfillableWarning",
69+
"Neo.ClientNotification.Schema.HintedIndexNotFound");
70+
71+
Set<String> cypherUnrecognizedNotificationCodes = Set.of(
72+
"Neo.ClientNotification.Database.HomeDatabaseNotFound",
5473
"Neo.ClientNotification.Statement.UnknownLabelWarning",
55-
"Neo.ClientNotification.Statement.UnknownPropertyKeyWarning",
56-
"Neo.ClientNotification.Statement.FeatureDeprecationWarning");
74+
"Neo.ClientNotification.Statement.UnknownRelationshipTypeWarning",
75+
"Neo.ClientNotification.Statement.UnknownPropertyKeyWarning");
76+
77+
Set<String> cypherUnsupportedNotificationCodes = Set.of(
78+
"Neo.ClientNotification.Statement.RuntimeUnsupportedWarning",
79+
"Neo.ClientNotification.Statement.RuntimeExperimental");
80+
81+
Set<String> cypherDeprecationNotificationCodes = Set.of(
82+
"Neo.ClientNotification.Statement.FeatureDeprecationWarning",
83+
"Neo.ClientNotification.Request.DeprecatedFormat");
84+
85+
Set<String> cypherGenericNotificationCodes = Set.of(
86+
"Neo.ClientNotification.Statement.SubqueryVariableShadowing",
87+
"Neo.ClientNotification.Statement.ParameterNotProvided",
88+
"Neo.ClientNotification.Procedure.ProcedureWarning",
89+
"Neo.ClientNotification.Statement.UnsatisfiableRelationshipTypeExpression",
90+
"Neo.ClientNotification.Statement.RepeatedRelationshipReference");
91+
5792

5893
static Neo4jClient create(Driver driver) {
5994

src/main/java/org/springframework/data/neo4j/core/ResultSummaries.java

+25-4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.neo4j.driver.summary.Notification;
2424
import org.neo4j.driver.summary.Plan;
2525
import org.neo4j.driver.summary.ResultSummary;
26+
import org.springframework.core.log.LogAccessor;
2627

2728
/**
2829
* Utility class for dealing with result summaries.
@@ -57,10 +58,7 @@ private static void logNotifications(ResultSummary resultSummary) {
5758
String query = resultSummary.query().text();
5859
resultSummary.notifications()
5960
.forEach(notification -> {
60-
var log = Neo4jClient.cypherNotificationCategories.contains(notification.code())
61-
? Neo4jClient.cypherNotificationLog
62-
: Neo4jClient.cypherLog;
63-
61+
LogAccessor log = getLogAccessor(notification.code());
6462
Consumer<String> logFunction =
6563
switch (notification.severity()) {
6664
case "WARNING" -> log::warn;
@@ -71,6 +69,29 @@ private static void logNotifications(ResultSummary resultSummary) {
7169
});
7270
}
7371

72+
private static LogAccessor getLogAccessor(String cypherCode) {
73+
if (Neo4jClient.cypherPerformanceNotificationCodes.contains(cypherCode)) {
74+
return Neo4jClient.cypherPerformanceNotificationLog;
75+
}
76+
if (Neo4jClient.cypherHintNotificationCodes.contains(cypherCode)) {
77+
return Neo4jClient.cypherHintNotificationLog;
78+
}
79+
if (Neo4jClient.cypherUnrecognizedNotificationCodes.contains(cypherCode)) {
80+
return Neo4jClient.cypherUnrecognizedNotificationLog;
81+
}
82+
if (Neo4jClient.cypherUnsupportedNotificationCodes.contains(cypherCode)) {
83+
return Neo4jClient.cypherUnsupportedNotificationLog;
84+
}
85+
if (Neo4jClient.cypherDeprecationNotificationCodes.contains(cypherCode)) {
86+
return Neo4jClient.cypherDeprecationNotificationLog;
87+
}
88+
if (Neo4jClient.cypherGenericNotificationCodes.contains(cypherCode)) {
89+
return Neo4jClient.cypherGenericNotificationLog;
90+
}
91+
92+
return Neo4jClient.cypherLog;
93+
}
94+
7495
/**
7596
* Creates a formatted string for a notification issued for a given query.
7697
*

src/test/resources/logback-test.xml

+7-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,13 @@
3030
<logger name="InboundMessageDispatcher" level="info"/>
3131

3232
<logger name="org.springframework.data.neo4j.cypher" level="info"/>
33-
<logger name="org.springframework.data.neo4j.cypher.notifications" level="error"/>
33+
<logger name="org.springframework.data.neo4j.cypher.performance" level="info"/>
34+
<logger name="org.springframework.data.neo4j.cypher.hint" level="info"/>
35+
<logger name="org.springframework.data.neo4j.cypher.unrecognized" level="error"/>
36+
<logger name="org.springframework.data.neo4j.cypher.unsupported" level="error"/>
37+
<!-- if deprecation gets set to "warn" or finer, all id() deprecation will get logged -->
38+
<logger name="org.springframework.data.neo4j.cypher.deprecation" level="error"/>
39+
<logger name="org.springframework.data.neo4j.cypher.generic" level="error"/>
3440
<logger name="org.springframework.data.neo4j" level="info"/>
3541
<logger name="org.springframework.data.neo4j.test" level="info"/>
3642
<logger name="org.springframework.data.neo4j.repository.query.Neo4jQuerySupport" level="debug" />

0 commit comments

Comments
 (0)