Skip to content

Commit 7bd12b1

Browse files
committed
Make Logger instance names qualified
1 parent a0d391b commit 7bd12b1

31 files changed

+126
-109
lines changed

driver/clirr-ignored-differences.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,10 @@
2525
<method>void debug(java.lang.String, java.lang.Throwable)</method>
2626
</difference>
2727

28+
<difference>
29+
<className>org/neo4j/driver/Logging</className>
30+
<differenceType>7012</differenceType>
31+
<method>org.neo4j.driver.Logger getLog(java.lang.Class)</method>
32+
</difference>
33+
2834
</differences>

driver/src/main/java/org/neo4j/driver/GraphDatabase.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@
3636
*/
3737
public class GraphDatabase
3838
{
39-
private static final String LOGGER_NAME = GraphDatabase.class.getSimpleName();
40-
4139
/**
4240
* Return a driver for a Neo4j instance with the default configuration settings
4341
*
@@ -206,7 +204,7 @@ private static void assertRoutingUris( Iterable<URI> uris )
206204
private static Logger createLogger( Config config )
207205
{
208206
Logging logging = getOrDefault( config ).logging();
209-
return logging.getLog( LOGGER_NAME );
207+
return logging.getLog( GraphDatabase.class );
210208
}
211209

212210
private static Config getOrDefault( Config config )

driver/src/main/java/org/neo4j/driver/Logging.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,18 @@
8787
*/
8888
public interface Logging
8989
{
90+
/**
91+
* Obtain a {@link Logger} instance by class, its name will be the fully qualified name of the class.
92+
*
93+
* @param clazz class whose name should be used as the {@link Logger} name.
94+
* @return {@link Logger} instance
95+
*/
96+
default Logger getLog( Class<?> clazz )
97+
{
98+
String canonicalName = clazz.getCanonicalName();
99+
return getLog( canonicalName != null ? canonicalName : clazz.getName() );
100+
}
101+
90102
/**
91103
* Obtain a {@link Logger} instance by name.
92104
*

driver/src/main/java/org/neo4j/driver/internal/DriverFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ protected InternalDriver createDirectDriver( SecurityPlan securityPlan, BoltServ
169169
ConnectionProvider connectionProvider = new DirectConnectionProvider( address, connectionPool );
170170
SessionFactory sessionFactory = createSessionFactory( connectionProvider, retryLogic, config );
171171
InternalDriver driver = createDriver( securityPlan, sessionFactory, metricsProvider, config );
172-
Logger log = config.logging().getLog( Driver.class.getSimpleName() );
172+
Logger log = config.logging().getLog( getClass() );
173173
log.info( "Direct driver instance %s created for server address %s", driver.hashCode(), address );
174174
return driver;
175175
}
@@ -186,7 +186,7 @@ protected InternalDriver createRoutingDriver( SecurityPlan securityPlan, BoltSer
186186
config, routingSettings );
187187
SessionFactory sessionFactory = createSessionFactory( connectionProvider, retryLogic, config );
188188
InternalDriver driver = createDriver( securityPlan, sessionFactory, metricsProvider, config );
189-
Logger log = config.logging().getLog( Driver.class.getSimpleName() );
189+
Logger log = config.logging().getLog( getClass() );
190190
log.info( "Routing driver instance %s created for server address %s", driver.hashCode(), address );
191191
return driver;
192192
}

driver/src/main/java/org/neo4j/driver/internal/InternalDriver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public class InternalDriver implements Driver
5454
this.securityPlan = securityPlan;
5555
this.sessionFactory = sessionFactory;
5656
this.metricsProvider = metricsProvider;
57-
this.log = logging.getLog( Driver.class.getSimpleName() );
57+
this.log = logging.getLog( getClass() );
5858
}
5959

6060
@Override

driver/src/main/java/org/neo4j/driver/internal/async/NetworkConnection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public class NetworkConnection implements Connection
7575

7676
public NetworkConnection( Channel channel, ExtendedChannelPool channelPool, Clock clock, MetricsListener metricsListener, Logging logging )
7777
{
78-
this.log = logging.getLog( this.getClass().getCanonicalName() );
78+
this.log = logging.getLog( getClass() );
7979
this.channel = channel;
8080
this.messageDispatcher = ChannelAttributes.messageDispatcher( channel );
8181
this.serverAgent = ChannelAttributes.serverAgent( channel );

driver/src/main/java/org/neo4j/driver/internal/async/NetworkSession.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@
4848

4949
public class NetworkSession
5050
{
51-
private static final String LOG_NAME = "Session";
52-
5351
private final ConnectionProvider connectionProvider;
5452
private final NetworkSessionConnectionContext connectionContext;
5553
private final AccessMode mode;
@@ -70,7 +68,7 @@ public NetworkSession( ConnectionProvider connectionProvider, RetryLogic retryLo
7068
this.connectionProvider = connectionProvider;
7169
this.mode = mode;
7270
this.retryLogic = retryLogic;
73-
this.logger = new PrefixedLogger( "[" + hashCode() + "]", logging.getLog( LOG_NAME ) );
71+
this.logger = new PrefixedLogger( "[" + hashCode() + "]", logging.getLog( getClass() ) );
7472
this.bookmarkHolder = bookmarkHolder;
7573
this.connectionContext = new NetworkSessionConnectionContext( databaseName, bookmarkHolder.getBookmark() );
7674
this.fetchSize = fetchSize;

driver/src/main/java/org/neo4j/driver/internal/async/pool/ConnectionPoolImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ protected ConnectionPoolImpl( ChannelConnector connector, Bootstrap bootstrap, N
8585
this.channelHealthChecker = nettyChannelHealthChecker;
8686
this.settings = settings;
8787
this.metricsListener = metricsListener;
88-
this.log = logging.getLog( ConnectionPool.class.getSimpleName() );
88+
this.log = logging.getLog( getClass() );
8989
this.ownsEventLoopGroup = ownsEventLoopGroup;
9090
this.connectionFactory = connectionFactory;
9191
}

driver/src/main/java/org/neo4j/driver/internal/async/pool/NettyChannelHealthChecker.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,16 @@ public class NettyChannelHealthChecker implements ChannelHealthChecker, Authoriz
4242
{
4343
private final PoolSettings poolSettings;
4444
private final Clock clock;
45+
private final Logging logging;
4546
private final Logger log;
4647
private final AtomicReference<Optional<Long>> minCreationTimestampMillisOpt;
4748

4849
public NettyChannelHealthChecker( PoolSettings poolSettings, Clock clock, Logging logging )
4950
{
5051
this.poolSettings = poolSettings;
5152
this.clock = clock;
52-
this.log = logging.getLog( getClass().getSimpleName() );
53+
this.logging = logging;
54+
this.log = logging.getLog( getClass() );
5355
this.minCreationTimestampMillisOpt = new AtomicReference<>( Optional.empty() );
5456
}
5557

@@ -129,7 +131,7 @@ private boolean hasBeenIdleForTooLong( Channel channel )
129131
private Future<Boolean> ping( Channel channel )
130132
{
131133
Promise<Boolean> result = channel.eventLoop().newPromise();
132-
messageDispatcher( channel ).enqueue( new PingResponseHandler( result, channel, log ) );
134+
messageDispatcher( channel ).enqueue( new PingResponseHandler( result, channel, logging ) );
133135
channel.writeAndFlush( ResetMessage.RESET, channel.voidPromise() );
134136
return result;
135137
}

driver/src/main/java/org/neo4j/driver/internal/async/pool/NettyChannelTracker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public NettyChannelTracker( MetricsListener metricsListener, EventExecutor event
6161
public NettyChannelTracker( MetricsListener metricsListener, ChannelGroup channels, Logging logging )
6262
{
6363
this.metricsListener = metricsListener;
64-
this.log = logging.getLog( getClass().getSimpleName() );
64+
this.log = logging.getLog( getClass() );
6565
this.allChannels = channels;
6666
}
6767

driver/src/main/java/org/neo4j/driver/internal/cluster/RediscoveryImpl.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
import org.neo4j.driver.Bookmark;
3535
import org.neo4j.driver.Logger;
36+
import org.neo4j.driver.Logging;
3637
import org.neo4j.driver.exceptions.DiscoveryException;
3738
import org.neo4j.driver.exceptions.FatalDiscoveryException;
3839
import org.neo4j.driver.exceptions.SecurityException;
@@ -69,11 +70,11 @@ public class RediscoveryImpl implements Rediscovery
6970
private final DomainNameResolver domainNameResolver;
7071

7172
public RediscoveryImpl( BoltServerAddress initialRouter, RoutingSettings settings, ClusterCompositionProvider provider,
72-
EventExecutorGroup eventExecutorGroup, ServerAddressResolver resolver, Logger logger, DomainNameResolver domainNameResolver )
73+
EventExecutorGroup eventExecutorGroup, ServerAddressResolver resolver, Logging logging, DomainNameResolver domainNameResolver )
7374
{
7475
this.initialRouter = initialRouter;
7576
this.settings = settings;
76-
this.logger = logger;
77+
this.logger = logging.getLog( getClass() );
7778
this.provider = provider;
7879
this.resolver = resolver;
7980
this.eventExecutorGroup = eventExecutorGroup;

driver/src/main/java/org/neo4j/driver/internal/cluster/RoutingTableHandlerImpl.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.util.concurrent.CompletionStage;
2626

2727
import org.neo4j.driver.Logger;
28+
import org.neo4j.driver.Logging;
2829
import org.neo4j.driver.internal.BoltServerAddress;
2930
import org.neo4j.driver.internal.DatabaseName;
3031
import org.neo4j.driver.internal.async.ConnectionContext;
@@ -45,15 +46,16 @@ public class RoutingTableHandlerImpl implements RoutingTableHandler
4546
private final long routingTablePurgeDelayMs;
4647
private final Set<BoltServerAddress> resolvedInitialRouters = new HashSet<>();
4748

48-
public RoutingTableHandlerImpl( RoutingTable routingTable, Rediscovery rediscovery, ConnectionPool connectionPool, RoutingTableRegistry routingTableRegistry,
49-
Logger log, long routingTablePurgeDelayMs )
49+
public RoutingTableHandlerImpl( RoutingTable routingTable, Rediscovery rediscovery, ConnectionPool connectionPool,
50+
RoutingTableRegistry routingTableRegistry,
51+
Logging logging, long routingTablePurgeDelayMs )
5052
{
5153
this.routingTable = routingTable;
5254
this.databaseName = routingTable.database();
5355
this.rediscovery = rediscovery;
5456
this.connectionPool = connectionPool;
5557
this.routingTableRegistry = routingTableRegistry;
56-
this.log = log;
58+
this.log = logging.getLog( getClass() );
5759
this.routingTablePurgeDelayMs = routingTablePurgeDelayMs;
5860
}
5961

driver/src/main/java/org/neo4j/driver/internal/cluster/RoutingTableRegistryImpl.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.util.concurrent.ConcurrentMap;
2727

2828
import org.neo4j.driver.Logger;
29+
import org.neo4j.driver.Logging;
2930
import org.neo4j.driver.internal.BoltServerAddress;
3031
import org.neo4j.driver.internal.DatabaseName;
3132
import org.neo4j.driver.internal.async.ConnectionContext;
@@ -38,16 +39,16 @@ public class RoutingTableRegistryImpl implements RoutingTableRegistry
3839
private final RoutingTableHandlerFactory factory;
3940
private final Logger logger;
4041

41-
public RoutingTableRegistryImpl( ConnectionPool connectionPool, Rediscovery rediscovery, Clock clock, Logger logger, long routingTablePurgeDelayMs )
42+
public RoutingTableRegistryImpl( ConnectionPool connectionPool, Rediscovery rediscovery, Clock clock, Logging logging, long routingTablePurgeDelayMs )
4243
{
43-
this( new ConcurrentHashMap<>(), new RoutingTableHandlerFactory( connectionPool, rediscovery, clock, logger, routingTablePurgeDelayMs ), logger );
44+
this( new ConcurrentHashMap<>(), new RoutingTableHandlerFactory( connectionPool, rediscovery, clock, logging, routingTablePurgeDelayMs ), logging );
4445
}
4546

46-
RoutingTableRegistryImpl( ConcurrentMap<DatabaseName,RoutingTableHandler> routingTableHandlers, RoutingTableHandlerFactory factory, Logger logger )
47+
RoutingTableRegistryImpl( ConcurrentMap<DatabaseName,RoutingTableHandler> routingTableHandlers, RoutingTableHandlerFactory factory, Logging logging )
4748
{
4849
this.factory = factory;
4950
this.routingTableHandlers = routingTableHandlers;
50-
this.logger = logger;
51+
this.logger = logging.getLog( getClass() );
5152
}
5253

5354
@Override
@@ -120,23 +121,25 @@ static class RoutingTableHandlerFactory
120121
{
121122
private final ConnectionPool connectionPool;
122123
private final Rediscovery rediscovery;
124+
private final Logging logging;
123125
private final Logger log;
124126
private final Clock clock;
125127
private final long routingTablePurgeDelayMs;
126128

127-
RoutingTableHandlerFactory( ConnectionPool connectionPool, Rediscovery rediscovery, Clock clock, Logger log, long routingTablePurgeDelayMs )
129+
RoutingTableHandlerFactory( ConnectionPool connectionPool, Rediscovery rediscovery, Clock clock, Logging logging, long routingTablePurgeDelayMs )
128130
{
129131
this.connectionPool = connectionPool;
130132
this.rediscovery = rediscovery;
131133
this.clock = clock;
132-
this.log = log;
134+
this.logging = logging;
135+
this.log = logging.getLog( getClass() );
133136
this.routingTablePurgeDelayMs = routingTablePurgeDelayMs;
134137
}
135138

136139
RoutingTableHandler newInstance( DatabaseName databaseName, RoutingTableRegistry allTables )
137140
{
138141
ClusterRoutingTable routingTable = new ClusterRoutingTable( databaseName, clock );
139-
return new RoutingTableHandlerImpl( routingTable, rediscovery, connectionPool, allTables, log, routingTablePurgeDelayMs );
142+
return new RoutingTableHandlerImpl( routingTable, rediscovery, connectionPool, allTables, logging, routingTablePurgeDelayMs );
140143
}
141144
}
142145
}

driver/src/main/java/org/neo4j/driver/internal/cluster/loadbalancing/LeastConnectedLoadBalancingStrategy.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
*/
1919
package org.neo4j.driver.internal.cluster.loadbalancing;
2020

21-
import org.neo4j.driver.internal.BoltServerAddress;
22-
import org.neo4j.driver.internal.spi.ConnectionPool;
2321
import org.neo4j.driver.Logger;
2422
import org.neo4j.driver.Logging;
23+
import org.neo4j.driver.internal.BoltServerAddress;
24+
import org.neo4j.driver.internal.spi.ConnectionPool;
2525

2626
/**
2727
* Load balancing strategy that finds server with least amount of active (checked out of the pool) connections from
@@ -30,8 +30,6 @@
3030
*/
3131
public class LeastConnectedLoadBalancingStrategy implements LoadBalancingStrategy
3232
{
33-
private static final String LOGGER_NAME = LeastConnectedLoadBalancingStrategy.class.getSimpleName();
34-
3533
private final RoundRobinArrayIndex readersIndex = new RoundRobinArrayIndex();
3634
private final RoundRobinArrayIndex writersIndex = new RoundRobinArrayIndex();
3735

@@ -41,7 +39,7 @@ public class LeastConnectedLoadBalancingStrategy implements LoadBalancingStrateg
4139
public LeastConnectedLoadBalancingStrategy( ConnectionPool connectionPool, Logging logging )
4240
{
4341
this.connectionPool = connectionPool;
44-
this.log = logging.getLog( LOGGER_NAME );
42+
this.log = logging.getLog( getClass() );
4543
}
4644

4745
@Override

driver/src/main/java/org/neo4j/driver/internal/cluster/loadbalancing/LoadBalancer.java

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@
6262

6363
public class LoadBalancer implements ConnectionProvider
6464
{
65-
private static final String LOAD_BALANCER_LOG_NAME = "LoadBalancer";
6665
private static final String CONNECTION_ACQUISITION_COMPLETION_FAILURE_MESSAGE = "Connection acquisition failed for all available addresses.";
6766
private static final String CONNECTION_ACQUISITION_COMPLETION_EXCEPTION_MESSAGE =
6867
"Failed to obtain connection towards %s server. Known routing table is: %s";
@@ -80,27 +79,25 @@ public LoadBalancer( BoltServerAddress initialRouter, RoutingSettings settings,
8079
LoadBalancingStrategy loadBalancingStrategy, ServerAddressResolver resolver, DomainNameResolver domainNameResolver )
8180
{
8281
this( connectionPool, createRediscovery( eventExecutorGroup, initialRouter, resolver, settings, clock, logging, requireNonNull( domainNameResolver ) ),
83-
settings,
84-
loadBalancingStrategy,
85-
eventExecutorGroup, clock, loadBalancerLogger( logging ) );
82+
settings, loadBalancingStrategy, eventExecutorGroup, clock, logging );
8683
}
8784

8885
private LoadBalancer( ConnectionPool connectionPool, Rediscovery rediscovery, RoutingSettings settings, LoadBalancingStrategy loadBalancingStrategy,
89-
EventExecutorGroup eventExecutorGroup, Clock clock, Logger log )
86+
EventExecutorGroup eventExecutorGroup, Clock clock, Logging logging )
9087
{
91-
this( connectionPool, createRoutingTables( connectionPool, rediscovery, settings, clock, log ), rediscovery, loadBalancingStrategy, eventExecutorGroup,
92-
log );
88+
this( connectionPool, createRoutingTables( connectionPool, rediscovery, settings, clock, logging ), rediscovery, loadBalancingStrategy,
89+
eventExecutorGroup, logging );
9390
}
9491

9592
LoadBalancer( ConnectionPool connectionPool, RoutingTableRegistry routingTables, Rediscovery rediscovery, LoadBalancingStrategy loadBalancingStrategy,
96-
EventExecutorGroup eventExecutorGroup, Logger log )
93+
EventExecutorGroup eventExecutorGroup, Logging logging )
9794
{
9895
this.connectionPool = connectionPool;
9996
this.routingTables = routingTables;
10097
this.rediscovery = rediscovery;
10198
this.loadBalancingStrategy = loadBalancingStrategy;
10299
this.eventExecutorGroup = eventExecutorGroup;
103-
this.log = log;
100+
this.log = logging.getLog( getClass() );
104101
}
105102

106103
@Override
@@ -269,22 +266,16 @@ private BoltServerAddress selectAddress( AccessMode mode, AddressSet servers )
269266
}
270267

271268
private static RoutingTableRegistry createRoutingTables( ConnectionPool connectionPool, Rediscovery rediscovery, RoutingSettings settings, Clock clock,
272-
Logger log )
269+
Logging logging )
273270
{
274-
return new RoutingTableRegistryImpl( connectionPool, rediscovery, clock, log, settings.routingTablePurgeDelayMs() );
271+
return new RoutingTableRegistryImpl( connectionPool, rediscovery, clock, logging, settings.routingTablePurgeDelayMs() );
275272
}
276273

277274
private static Rediscovery createRediscovery( EventExecutorGroup eventExecutorGroup, BoltServerAddress initialRouter, ServerAddressResolver resolver,
278275
RoutingSettings settings, Clock clock, Logging logging, DomainNameResolver domainNameResolver )
279276
{
280-
Logger log = loadBalancerLogger( logging );
281277
ClusterCompositionProvider clusterCompositionProvider = new RoutingProcedureClusterCompositionProvider( clock, settings.routingContext() );
282-
return new RediscoveryImpl( initialRouter, settings, clusterCompositionProvider, eventExecutorGroup, resolver, log, domainNameResolver );
283-
}
284-
285-
private static Logger loadBalancerLogger( Logging logging )
286-
{
287-
return logging.getLog( LOAD_BALANCER_LOG_NAME );
278+
return new RediscoveryImpl( initialRouter, settings, clusterCompositionProvider, eventExecutorGroup, resolver, logging, domainNameResolver );
288279
}
289280

290281
private static RuntimeException unknownMode( AccessMode mode )

driver/src/main/java/org/neo4j/driver/internal/handlers/PingResponseHandler.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,22 @@
2323

2424
import java.util.Map;
2525

26-
import org.neo4j.driver.internal.spi.ResponseHandler;
2726
import org.neo4j.driver.Logger;
27+
import org.neo4j.driver.Logging;
2828
import org.neo4j.driver.Value;
29+
import org.neo4j.driver.internal.spi.ResponseHandler;
2930

3031
public class PingResponseHandler implements ResponseHandler
3132
{
3233
private final Promise<Boolean> result;
3334
private final Channel channel;
3435
private final Logger log;
3536

36-
public PingResponseHandler( Promise<Boolean> result, Channel channel, Logger log )
37+
public PingResponseHandler( Promise<Boolean> result, Channel channel, Logging logging )
3738
{
3839
this.result = result;
3940
this.channel = channel;
40-
this.log = log;
41+
this.log = logging.getLog( getClass() );
4142
}
4243

4344
@Override

0 commit comments

Comments
 (0)