Skip to content

feat(logging): add support for System.Logger and deprecate Logging #1648

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 6.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.neo4j.driver.AuthTokens;
import org.neo4j.driver.Logging;

@SuppressWarnings("deprecation")
public record Config(int port, URI uri, AuthToken authToken, Logging logging) {
static Config load() {
var env = System.getenv();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
public class Runner {
public static void main(String[] args) throws InterruptedException {
var config = Config.load();
@SuppressWarnings("deprecation")
var driver = GraphDatabase.driver(
config.uri(),
config.authToken(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,14 @@ public class HttpRequestHandler extends SimpleChannelInboundHandler<FullHttpRequ
private final ObjectMapper objectMapper = new ObjectMapper();
private final WorkloadHandler workloadHandler;
private final ReadyHandler readyHandler;

@SuppressWarnings("deprecation")
private final Logger logger;

public HttpRequestHandler(WorkloadHandler workloadHandler, ReadyHandler readyHandler, Logging logging) {
public HttpRequestHandler(
WorkloadHandler workloadHandler,
ReadyHandler readyHandler,
@SuppressWarnings("deprecation") Logging logging) {
this.workloadHandler = Objects.requireNonNull(workloadHandler);
this.readyHandler = Objects.requireNonNull(readyHandler);
this.logger = logging.getLog(getClass());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@

public class ReadyHandler {
private final Driver driver;

@SuppressWarnings("deprecation")
private final Logger logger;

public ReadyHandler(Driver driver, Logging logging) {
public ReadyHandler(Driver driver, @SuppressWarnings("deprecation") Logging logging) {
this.driver = driver;
this.logger = logging.getLog(getClass());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@
public class WorkloadHandler {
private final Driver driver;
private final Executor executor;

@SuppressWarnings("deprecation")
private final Logger logger;

public WorkloadHandler(Driver driver, Executor executor, Logging logging) {
public WorkloadHandler(Driver driver, Executor executor, @SuppressWarnings("deprecation") Logging logging) {
this.driver = Objects.requireNonNull(driver);
this.executor = Objects.requireNonNull(executor);
this.logger = logging.getLog(getClass());
Expand Down
6 changes: 6 additions & 0 deletions driver/clirr-ignored-differences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -770,4 +770,10 @@
<differenceType>8001</differenceType>
</difference>

<difference>
<className>org/neo4j/driver/Logging</className>
<differenceType>7012</differenceType>
<method>org.neo4j.driver.Logging systemLogging()</method>
</difference>

</differences>
13 changes: 9 additions & 4 deletions driver/src/main/java/org/neo4j/driver/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package org.neo4j.driver;

import static java.lang.String.format;
import static org.neo4j.driver.internal.logging.DevNullLogging.DEV_NULL_LOGGING;
import static org.neo4j.driver.internal.util.DriverInfoUtil.driverVersion;

import io.netty.channel.EventLoop;
Expand All @@ -32,7 +31,6 @@
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.stream.Collectors;
import org.neo4j.driver.async.AsyncSession;
import org.neo4j.driver.exceptions.UnsupportedFeatureException;
Expand Down Expand Up @@ -83,6 +81,7 @@ public final class Config implements Serializable {
/**
* User defined logging
*/
@SuppressWarnings("deprecation")
private final Logging logging;

/**
Expand Down Expand Up @@ -187,7 +186,9 @@ private Config(ConfigBuilder builder) {
* Logging provider
*
* @return the Logging provider to use
* @deprecated the logging abstraction has been deprecated in favour of the {@link System.Logger}
*/
@Deprecated
public Logging logging() {
return logging;
}
Expand Down Expand Up @@ -408,7 +409,9 @@ public boolean isTelemetryDisabled() {
* Used to build new config instances
*/
public static final class ConfigBuilder {
private Logging logging = DEV_NULL_LOGGING;
@SuppressWarnings("deprecation")
private Logging logging = Logging.systemLogging();

private boolean logLeakedSessions;
private int maxConnectionPoolSize = 100;
private long idleTimeBeforeConnectionTest = -1;
Expand All @@ -432,7 +435,7 @@ public static final class ConfigBuilder {
private ConfigBuilder() {}

/**
* Provide a logging implementation for the driver to use. Java logging framework {@link java.util.logging} with {@link Level#INFO} is used by default.
* Provide a logging implementation for the driver to use. {@link Logging#systemLogging()} is used by default.
* Callers are expected to either implement {@link Logging} interface or provide one of the existing implementations available from static factory
* methods in the {@link Logging} interface.
* <p>
Expand All @@ -441,7 +444,9 @@ private ConfigBuilder() {}
* @param logging the logging instance to use
* @return this builder
* @see Logging
* @deprecated the logging abstraction has been deprecated in favour of the {@link System.Logger}
*/
@Deprecated
public ConfigBuilder withLogging(Logging logging) {
this.logging = logging;
return this;
Expand Down
1 change: 1 addition & 0 deletions driver/src/main/java/org/neo4j/driver/GraphDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ private static Driver driver(
return driverFactory.newInstance(uri, new StaticAuthTokenManager(authToken), clientCertificateManager, config);
}

@SuppressWarnings("deprecation")
private static Driver driver(
URI uri,
AuthTokenManager authTokenManager,
Expand Down
2 changes: 2 additions & 0 deletions driver/src/main/java/org/neo4j/driver/Logger.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
* message only if the needed logging level is enabled. Driver expects formatting to be done using {@link String#format(String, Object...)} method.
* Thus, all supplied message templates will contain "%s" as parameter placeholders. This is different from all SLF4J-compatible logging frameworks
* where parameter placeholder is "{}". Implementations of this interface should adapt placeholders from "%s" to "{}", if required.
* @deprecated the logging abstraction has been deprecated in favour of the {@link System.Logger}
*/
@Deprecated
public interface Logger {
/**
* Logs errors from this driver.
Expand Down
13 changes: 13 additions & 0 deletions driver/src/main/java/org/neo4j/driver/Logging.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.neo4j.driver.internal.logging.ConsoleLogging;
import org.neo4j.driver.internal.logging.JULogging;
import org.neo4j.driver.internal.logging.Slf4jLogging;
import org.neo4j.driver.internal.logging.SystemLogging;

/**
* Accessor for {@link Logger} instances. Configured once for a driver instance using {@link Config.ConfigBuilder#withLogging(Logging)} builder method.
Expand Down Expand Up @@ -82,7 +83,9 @@
*
* @see Logger
* @see Config.ConfigBuilder#withLogging(Logging)
* @deprecated the logging abstraction has been deprecated in favour of the {@link System.Logger}
*/
@Deprecated
public interface Logging extends Serializable {
/**
* Obtain a {@link Logger} instance by class, its name will be the fully qualified name of the class.
Expand All @@ -103,6 +106,16 @@ default Logger getLog(Class<?> clazz) {
*/
Logger getLog(String name);

/**
* Returns logging implementation that uses {@link System.Logger}.
*
* @return logging implementation
* @since 6.0.0
*/
static Logging systemLogging() {
return SystemLogging.INSTANCE;
}

/**
* Create logging implementation that uses SLF4J.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
import org.neo4j.driver.Logger;

public class BoltLogger implements System.Logger {
@SuppressWarnings("deprecation")
private final Logger logger;

public BoltLogger(Logger logger) {
public BoltLogger(@SuppressWarnings("deprecation") Logger logger) {
this.logger = logger;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
import org.neo4j.driver.Logging;

public class BoltLoggingProvider implements LoggingProvider {
@SuppressWarnings("deprecation")
private final Logging logging;

public BoltLoggingProvider(Logging logging) {
public BoltLoggingProvider(@SuppressWarnings("deprecation") Logging logging) {
this.logging = logging;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public final Driver newInstance(
return newInstance(uri, authTokenManager, clientCertificateManager, config, null, null, null);
}

@SuppressWarnings("deprecation")
public final Driver newInstance(
URI uri,
AuthTokenManager authTokenManager,
Expand Down Expand Up @@ -141,6 +142,7 @@ public final Driver newInstance(
rediscoverySupplier);
}

@SuppressWarnings("deprecation")
protected static MetricsProvider getOrCreateMetricsProvider(Config config, Clock clock) {
var metricsAdapter = config.metricsAdapter();
// This can actually only happen when someone mocks the config
Expand All @@ -154,6 +156,7 @@ protected static MetricsProvider getOrCreateMetricsProvider(Config config, Clock
};
}

@SuppressWarnings("deprecation")
private InternalDriver createDriver(
URI uri,
BoltSecurityPlanManager securityPlanManager,
Expand Down Expand Up @@ -263,6 +266,7 @@ private DriverBoltConnectionProvider createDriverBoltConnectionProvider(
connectTimeoutMillis);
}

@SuppressWarnings("deprecation")
protected BoltConnectionProvider createBoltConnectionProvider(
URI uri,
Config config,
Expand Down Expand Up @@ -397,6 +401,7 @@ protected LocalAddress localAddress() {
* <p>
* <b>This method is protected only for testing</b>
*/
@SuppressWarnings("deprecation")
protected InternalDriver createDriver(
BoltSecurityPlanManager securityPlanManager,
SessionFactory sessionFactory,
Expand Down Expand Up @@ -442,7 +447,9 @@ protected SessionFactory createSessionFactory(
* <b>This method is protected only for testing</b>
*/
protected RetryLogic createRetryLogic(
long maxTransactionRetryTime, EventExecutorGroup eventExecutorGroup, Logging logging) {
long maxTransactionRetryTime,
EventExecutorGroup eventExecutorGroup,
@SuppressWarnings("deprecation") Logging logging) {
return new ExponentialBackoffRetryLogic(maxTransactionRetryTime, eventExecutorGroup, createClock(), logging);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public class InternalDriver implements Driver {
BookmarkManagers.defaultManager(BookmarkManagerConfig.builder().build());
private final BoltSecurityPlanManager securityPlanManager;
private final SessionFactory sessionFactory;

@SuppressWarnings("deprecation")
private final Logger log;

private final boolean telemetryDisabled;
Expand All @@ -77,7 +79,7 @@ public class InternalDriver implements Driver {
boolean telemetryDisabled,
NotificationConfig notificationConfig,
Supplier<CompletionStage<Void>> shutdownSupplier,
Logging logging) {
@SuppressWarnings("deprecation") Logging logging) {
this.securityPlanManager = securityPlanManager;
this.sessionFactory = sessionFactory;
this.metricsProvider = metricsProvider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,16 @@ public class SessionFactoryImpl implements SessionFactory {
private final BoltSecurityPlanManager securityPlanManager;
private final DriverBoltConnectionProvider connectionProvider;
private final RetryLogic retryLogic;

@SuppressWarnings("deprecation")
private final Logging logging;

private final boolean leakedSessionsLoggingEnabled;
private final long defaultFetchSize;
private final AuthTokenManager authTokenManager;
private final HomeDatabaseCache homeDatabaseCache;

@SuppressWarnings("deprecation")
SessionFactoryImpl(
BoltSecurityPlanManager securityPlanManager,
DriverBoltConnectionProvider connectionProvider,
Expand Down Expand Up @@ -167,7 +171,7 @@ private NetworkSession createSession(
Set<Bookmark> bookmarks,
long fetchSize,
String impersonatedUser,
Logging logging,
@SuppressWarnings("deprecation") Logging logging,
BookmarkManager bookmarkManager,
NotificationConfig driverNotificationConfig,
NotificationConfig notificationConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public LeakLoggingNetworkSession(
Set<Bookmark> bookmarks,
String impersonatedUser,
long fetchSize,
Logging logging,
@SuppressWarnings("deprecation") Logging logging,
BookmarkManager bookmarkManager,
NotificationConfig driverNotificationConfig,
NotificationConfig notificationConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,11 @@ public class NetworkSession {
private final NetworkSessionConnectionContext connectionContext;
private final AccessMode mode;
private final RetryLogic retryLogic;

@SuppressWarnings("deprecation")
private final Logging logging;

@SuppressWarnings("deprecation")
protected final Logger log;

private final long fetchSize;
Expand Down Expand Up @@ -122,7 +126,7 @@ public NetworkSession(
Set<Bookmark> bookmarks,
String impersonatedUser,
long fetchSize,
Logging logging,
@SuppressWarnings("deprecation") Logging logging,
BookmarkManager bookmarkManager,
org.neo4j.driver.NotificationConfig driverNotificationConfig,
org.neo4j.driver.NotificationConfig notificationConfig,
Expand Down Expand Up @@ -723,7 +727,10 @@ public AuthToken overrideAuthToken() {
public static class RunRxResponseHandler implements DriverResponseHandler {
private static final Lock NOOP_LOCK = new NoopLock();
final CompletableFuture<RxResultCursor> cursorFuture = new CompletableFuture<>();

@SuppressWarnings("deprecation")
private final Logging logging;

private final DriverBoltConnection connection;
private final Query query;
private final Consumer<DatabaseBookmark> bookmarkConsumer;
Expand All @@ -734,7 +741,7 @@ public static class RunRxResponseHandler implements DriverResponseHandler {
private int ignoredCount;

public RunRxResponseHandler(
Logging logging,
@SuppressWarnings("deprecation") Logging logging,
DriverBoltConnection connection,
Query query,
Consumer<DatabaseBookmark> bookmarkConsumer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,17 @@
import org.neo4j.driver.internal.util.Futures;

final class TerminationAwareBoltConnection extends DelegatingBoltConnection {
@SuppressWarnings("deprecation")
private final Logging logging;

@SuppressWarnings("deprecation")
private final Logger log;

private final TerminationAwareStateLockingExecutor executor;
private final Consumer<Throwable> throwableConsumer;

public TerminationAwareBoltConnection(
Logging logging,
@SuppressWarnings("deprecation") Logging logging,
DriverBoltConnection delegate,
TerminationAwareStateLockingExecutor executor,
Consumer<Throwable> throwableConsumer) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@
import org.neo4j.driver.internal.util.Futures;

final class TerminationAwareResponseHandler extends DelegatingResponseHandler {
@SuppressWarnings("deprecation")
private final Logger log;

private final TerminationAwareStateLockingExecutor executor;
private final Consumer<Throwable> throwableConsumer;

TerminationAwareResponseHandler(
Logging logging,
@SuppressWarnings("deprecation") Logging logging,
DriverResponseHandler delegate,
TerminationAwareStateLockingExecutor executor,
Consumer<Throwable> throwableConsumer) {
Expand Down
Loading