Skip to content

Commit 15c4c27

Browse files
committed
feat(logging): add support for System.Logger and deprecate Logging
BREAKING CHANGE: the default driver logging implementation has been changed from `Logging#none()` to `Logging.systemLogging()`. The logging abstraction has been deprecated in favour of the `System.Logger`. Specifically, this applies to the following: - `org.neo4j.driver.Logging` - `org.neo4j.driver.Logger` - `org.neo4j.driver.Config.ConfigBuilder#withLogging(Logging)` - `org.neo4j.driver.Config#logging()` Once the logging abstraction is deleted, the driver is expected to use the `System.Logger` only.
1 parent 22b55b0 commit 15c4c27

File tree

95 files changed

+1399
-111
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+1399
-111
lines changed

benchkit-backend/src/main/java/neo4j/org/testkit/backend/Config.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,10 @@
1717
package neo4j.org.testkit.backend;
1818

1919
import java.net.URI;
20-
import java.util.logging.Level;
2120
import org.neo4j.driver.AuthToken;
2221
import org.neo4j.driver.AuthTokens;
23-
import org.neo4j.driver.Logging;
2422

25-
public record Config(int port, URI uri, AuthToken authToken, Logging logging) {
23+
public record Config(int port, URI uri, AuthToken authToken) {
2624
static Config load() {
2725
var env = System.getenv();
2826
var port = Integer.parseInt(env.getOrDefault("TEST_BACKEND_PORT", "9000"));
@@ -31,12 +29,9 @@ static Config load() {
3129
var neo4jScheme = env.getOrDefault("TEST_NEO4J_SCHEME", "neo4j");
3230
var neo4jUser = env.getOrDefault("TEST_NEO4J_USER", "neo4j");
3331
var neo4jPassword = env.getOrDefault("TEST_NEO4J_PASS", "password");
34-
var level = env.get("TEST_BACKEND_LOGGING_LEVEL");
35-
var logging = level == null || level.isEmpty() ? Logging.none() : Logging.console(Level.parse(level));
3632
return new Config(
3733
port,
3834
URI.create(String.format("%s://%s:%d", neo4jScheme, neo4jHost, neo4jPort)),
39-
AuthTokens.basic(neo4jUser, neo4jPassword),
40-
logging);
35+
AuthTokens.basic(neo4jUser, neo4jPassword));
4136
}
4237
}

benchkit-backend/src/main/java/neo4j/org/testkit/backend/Runner.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,12 @@
3333
public class Runner {
3434
public static void main(String[] args) throws InterruptedException {
3535
var config = Config.load();
36-
var driver = GraphDatabase.driver(
37-
config.uri(),
38-
config.authToken(),
39-
org.neo4j.driver.Config.builder().withLogging(config.logging()).build());
36+
var driver = GraphDatabase.driver(config.uri(), config.authToken());
4037

4138
EventLoopGroup group = new NioEventLoopGroup();
42-
var logging = config.logging();
4339
var executor = Executors.newCachedThreadPool();
44-
var workloadHandler = new WorkloadHandler(driver, executor, logging);
45-
var readyHandler = new ReadyHandler(driver, logging);
40+
var workloadHandler = new WorkloadHandler(driver, executor);
41+
var readyHandler = new ReadyHandler(driver);
4642
try {
4743
var bootstrap = new ServerBootstrap();
4844
bootstrap
@@ -55,7 +51,7 @@ protected void initChannel(SocketChannel channel) {
5551
var pipeline = channel.pipeline();
5652
pipeline.addLast("codec", new HttpServerCodec());
5753
pipeline.addLast("aggregator", new HttpObjectAggregator(512 * 1024));
58-
pipeline.addLast(new HttpRequestHandler(workloadHandler, readyHandler, logging));
54+
pipeline.addLast(new HttpRequestHandler(workloadHandler, readyHandler));
5955
}
6056
});
6157
var server = bootstrap.bind().sync();

benchkit-backend/src/main/java/neo4j/org/testkit/backend/channel/handler/HttpRequestHandler.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,16 @@
3737
import neo4j.org.testkit.backend.handler.ReadyHandler;
3838
import neo4j.org.testkit.backend.handler.WorkloadHandler;
3939
import neo4j.org.testkit.backend.request.WorkloadRequest;
40-
import org.neo4j.driver.Logger;
41-
import org.neo4j.driver.Logging;
4240

4341
public class HttpRequestHandler extends SimpleChannelInboundHandler<FullHttpRequest> {
42+
private static final System.Logger LOGGER = System.getLogger(WorkloadHandler.class.getName());
4443
private final ObjectMapper objectMapper = new ObjectMapper();
4544
private final WorkloadHandler workloadHandler;
4645
private final ReadyHandler readyHandler;
47-
private final Logger logger;
4846

49-
public HttpRequestHandler(WorkloadHandler workloadHandler, ReadyHandler readyHandler, Logging logging) {
47+
public HttpRequestHandler(WorkloadHandler workloadHandler, ReadyHandler readyHandler) {
5048
this.workloadHandler = Objects.requireNonNull(workloadHandler);
5149
this.readyHandler = Objects.requireNonNull(readyHandler);
52-
this.logger = logging.getLog(getClass());
5350
}
5451

5552
@Override
@@ -73,7 +70,8 @@ public void channelRead0(ChannelHandlerContext ctx, FullHttpRequest request) {
7370
} else if ("/ready".equals(request.uri()) && HttpMethod.GET.equals(request.method())) {
7471
responseStage = readyHandler.ready(request.protocolVersion());
7572
} else {
76-
logger.warn("Unknown request %s with %s method.", request.uri(), request.method());
73+
LOGGER.log(
74+
System.Logger.Level.WARNING, "Unknown request %s with %s method.", request.uri(), request.method());
7775
responseStage = CompletableFuture.completedFuture(
7876
new DefaultFullHttpResponse(request.protocolVersion(), HttpResponseStatus.INTERNAL_SERVER_ERROR));
7977
}
@@ -90,7 +88,7 @@ private static void send100Continue(ChannelHandlerContext ctx) {
9088

9189
@Override
9290
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
93-
logger.error("An unexpected error occured.", cause);
91+
LOGGER.log(System.Logger.Level.ERROR, "An unexpected error occured.", cause);
9492
ctx.close();
9593
}
9694
}

benchkit-backend/src/main/java/neo4j/org/testkit/backend/handler/ReadyHandler.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,13 @@
2323
import java.util.concurrent.CompletableFuture;
2424
import java.util.concurrent.CompletionStage;
2525
import org.neo4j.driver.Driver;
26-
import org.neo4j.driver.Logger;
27-
import org.neo4j.driver.Logging;
2826

2927
public class ReadyHandler {
28+
private static final System.Logger LOGGER = System.getLogger(ReadyHandler.class.getName());
3029
private final Driver driver;
31-
private final Logger logger;
3230

33-
public ReadyHandler(Driver driver, Logging logging) {
31+
public ReadyHandler(Driver driver) {
3432
this.driver = driver;
35-
this.logger = logging.getLog(getClass());
3633
}
3734

3835
public CompletionStage<FullHttpResponse> ready(HttpVersion httpVersion) {
@@ -41,7 +38,7 @@ public CompletionStage<FullHttpResponse> ready(HttpVersion httpVersion) {
4138
.handle((ignored, throwable) -> {
4239
HttpResponseStatus status;
4340
if (throwable != null) {
44-
logger.error("An error occured during workload handling.", throwable);
41+
LOGGER.log(System.Logger.Level.ERROR, "An error occured during workload handling.", throwable);
4542
status = HttpResponseStatus.INTERNAL_SERVER_ERROR;
4643
} else {
4744
status = HttpResponseStatus.NO_CONTENT;

benchkit-backend/src/main/java/neo4j/org/testkit/backend/handler/WorkloadHandler.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333
import neo4j.org.testkit.backend.request.WorkloadRequest;
3434
import org.neo4j.driver.AccessMode;
3535
import org.neo4j.driver.Driver;
36-
import org.neo4j.driver.Logger;
37-
import org.neo4j.driver.Logging;
3836
import org.neo4j.driver.QueryConfig;
3937
import org.neo4j.driver.RoutingControl;
4038
import org.neo4j.driver.Session;
@@ -43,14 +41,13 @@
4341
import org.neo4j.driver.TransactionCallback;
4442

4543
public class WorkloadHandler {
44+
private static final System.Logger LOGGER = System.getLogger(WorkloadHandler.class.getName());
4645
private final Driver driver;
4746
private final Executor executor;
48-
private final Logger logger;
4947

50-
public WorkloadHandler(Driver driver, Executor executor, Logging logging) {
48+
public WorkloadHandler(Driver driver, Executor executor) {
5149
this.driver = Objects.requireNonNull(driver);
5250
this.executor = Objects.requireNonNull(executor);
53-
this.logger = logging.getLog(getClass());
5451
}
5552

5653
public CompletionStage<FullHttpResponse> handle(HttpVersion httpVersion, WorkloadRequest workloadRequest) {
@@ -67,7 +64,7 @@ public CompletionStage<FullHttpResponse> handle(HttpVersion httpVersion, Workloa
6764
.handle((ignored, throwable) -> {
6865
HttpResponseStatus status;
6966
if (throwable != null) {
70-
logger.error("An error occured during workload handling.", throwable);
67+
LOGGER.log(System.Logger.Level.ERROR, "An error occured during workload handling.", throwable);
7168
status = HttpResponseStatus.INTERNAL_SERVER_ERROR;
7269
} else {
7370
status = HttpResponseStatus.NO_CONTENT;

driver-it/LICENSES.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
This file contains the full license text of the included third party
2+
libraries. For an overview of the licenses see the NOTICE.txt file.
3+
4+
5+

driver-it/NOTICE.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Copyright (c) "Neo4j"
2+
Neo4j Sweden AB [https://neo4j.com]
3+
4+
This file is part of Neo4j.
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.
14+
15+
Full license texts are found in LICENSES.txt.
16+
17+
18+
Third-party licenses
19+
--------------------
20+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
This file contains the full license text of the included third party
2+
libraries. For an overview of the licenses see the NOTICE.txt file.
3+
4+
5+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Copyright (c) "Neo4j"
2+
Neo4j Sweden AB [https://neo4j.com]
3+
4+
This file is part of Neo4j.
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.
14+
15+
Full license texts are found in LICENSES.txt.
16+
17+
18+
Third-party licenses
19+
--------------------
20+
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
3+
http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<parent>
7+
<groupId>org.neo4j.driver</groupId>
8+
<artifactId>neo4j-java-driver-it</artifactId>
9+
<version>6.0-SNAPSHOT</version>
10+
</parent>
11+
12+
<artifactId>neo4j-java-driver-jul-to-slf4j-log4j-it</artifactId>
13+
14+
<packaging>jar</packaging>
15+
<name>Neo4j Java Driver (JUL to SLF4J with Log4j IT)</name>
16+
17+
<scm>
18+
<connection>scm:git:git://github.com/neo4j/neo4j-java-driver.git</connection>
19+
<developerConnection>scm:git:[email protected]:neo4j/neo4j-java-driver.git</developerConnection>
20+
<url>https://github.com/neo4j/neo4j-java-driver</url>
21+
</scm>
22+
23+
<dependencies>
24+
<dependency>
25+
<groupId>org.neo4j.driver</groupId>
26+
<artifactId>neo4j-java-driver</artifactId>
27+
<version>${project.version}</version>
28+
<scope>test</scope>
29+
</dependency>
30+
<dependency>
31+
<groupId>org.slf4j</groupId>
32+
<artifactId>jul-to-slf4j</artifactId>
33+
<scope>test</scope>
34+
</dependency>
35+
<dependency>
36+
<groupId>org.apache.logging.log4j</groupId>
37+
<artifactId>log4j-slf4j2-impl</artifactId>
38+
<scope>test</scope>
39+
</dependency>
40+
<dependency>
41+
<groupId>org.apache.logging.log4j</groupId>
42+
<artifactId>log4j-core</artifactId>
43+
<scope>test</scope>
44+
</dependency>
45+
<dependency>
46+
<groupId>org.junit.jupiter</groupId>
47+
<artifactId>junit-jupiter</artifactId>
48+
</dependency>
49+
</dependencies>
50+
51+
<build>
52+
<plugins>
53+
<plugin>
54+
<groupId>org.apache.maven.plugins</groupId>
55+
<artifactId>maven-failsafe-plugin</artifactId>
56+
</plugin>
57+
</plugins>
58+
<pluginManagement>
59+
<plugins>
60+
<plugin>
61+
<groupId>org.apache.maven.plugins</groupId>
62+
<artifactId>maven-compiler-plugin</artifactId>
63+
<configuration>
64+
<compilerArgs>
65+
<arg>-proc:none</arg>
66+
</compilerArgs>
67+
</configuration>
68+
</plugin>
69+
</plugins>
70+
</pluginManagement>
71+
</build>
72+
73+
</project>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright (c) "Neo4j"
3+
* Neo4j Sweden AB [https://neo4j.com]
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.neo4j.driver.it.jul.to.slf4j;
18+
19+
import java.util.ArrayList;
20+
import java.util.List;
21+
import org.apache.logging.log4j.core.Filter;
22+
import org.apache.logging.log4j.core.LogEvent;
23+
import org.apache.logging.log4j.core.appender.AbstractAppender;
24+
import org.apache.logging.log4j.core.layout.PatternLayout;
25+
26+
final class InMemoryAppender extends AbstractAppender {
27+
private final List<LogEvent> logEvents = new ArrayList<>();
28+
29+
InMemoryAppender(String name, Filter filter) {
30+
super(name, filter, PatternLayout.createDefaultLayout(), false, null);
31+
start();
32+
}
33+
34+
@Override
35+
public void append(LogEvent event) {
36+
logEvents.add(event);
37+
}
38+
39+
List<LogEvent> getLogs() {
40+
return logEvents;
41+
}
42+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright (c) "Neo4j"
3+
* Neo4j Sweden AB [https://neo4j.com]
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.neo4j.driver.it.jul.to.slf4j;
18+
19+
import static org.junit.jupiter.api.Assertions.assertFalse;
20+
21+
import org.apache.logging.log4j.Level;
22+
import org.apache.logging.log4j.LogManager;
23+
import org.apache.logging.log4j.core.Logger;
24+
import org.apache.logging.log4j.core.config.Configurator;
25+
import org.junit.jupiter.api.BeforeEach;
26+
import org.junit.jupiter.api.Test;
27+
import org.neo4j.driver.GraphDatabase;
28+
import org.neo4j.driver.internal.DriverFactory;
29+
import org.slf4j.bridge.SLF4JBridgeHandler;
30+
31+
class LoggingIT {
32+
33+
private InMemoryAppender appender;
34+
35+
@BeforeEach
36+
void setup() {
37+
java.util.logging.LogManager.getLogManager().reset();
38+
SLF4JBridgeHandler.removeHandlersForRootLogger();
39+
SLF4JBridgeHandler.install();
40+
var julLogger = java.util.logging.Logger.getLogger(DriverFactory.class.getName());
41+
julLogger.setLevel(java.util.logging.Level.INFO);
42+
43+
Configurator.setLevel(DriverFactory.class.getName(), Level.INFO);
44+
var logger = (Logger) LogManager.getLogger(DriverFactory.class.getName());
45+
appender = new InMemoryAppender("Appender", null);
46+
logger.addAppender(appender);
47+
logger.setAdditive(false);
48+
}
49+
50+
@Test
51+
void shouldLog() {
52+
var driver = GraphDatabase.driver("bolt://localhost:7687");
53+
54+
assertFalse(appender.getLogs().isEmpty());
55+
}
56+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
This file contains the full license text of the included third party
2+
libraries. For an overview of the licenses see the NOTICE.txt file.
3+
4+
5+

0 commit comments

Comments
 (0)