Skip to content

Commit 5b83551

Browse files
authored
Make Logger instance names qualified (#973)
1 parent a0d391b commit 5b83551

32 files changed

+137
-122
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/LeakLoggingNetworkSession.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ private void logLeakIfNeeded()
5151
Boolean isOpen = Futures.blockingGet( currentConnectionIsOpen() );
5252
if ( isOpen )
5353
{
54-
logger.error( "Neo4j Session object leaked, please ensure that your application " +
55-
"fully consumes results in Sessions or explicitly calls `close` on Sessions before disposing of the objects.\n" +
56-
"Session was create at:\n" + stackTrace, null );
54+
log.error( "Neo4j Session object leaked, please ensure that your application " +
55+
"fully consumes results in Sessions or explicitly calls `close` on Sessions before disposing of the objects.\n" +
56+
"Session was create at:\n" + stackTrace, null );
5757
}
5858
}
5959
private static String captureStackTrace()

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: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,11 @@
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;
5654
private final RetryLogic retryLogic;
57-
protected final Logger logger;
55+
protected final Logger log;
5856

5957
private final BookmarkHolder bookmarkHolder;
6058
private final long fetchSize;
@@ -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.log = 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: 7 additions & 6 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;
@@ -62,18 +63,18 @@ public class RediscoveryImpl implements Rediscovery
6263

6364
private final BoltServerAddress initialRouter;
6465
private final RoutingSettings settings;
65-
private final Logger logger;
66+
private final Logger log;
6667
private final ClusterCompositionProvider provider;
6768
private final ServerAddressResolver resolver;
6869
private final EventExecutorGroup eventExecutorGroup;
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.log = logging.getLog( getClass() );
7778
this.provider = provider;
7879
this.resolver = resolver;
7980
this.eventExecutorGroup = eventExecutorGroup;
@@ -127,7 +128,7 @@ else if ( compositionLookupResult != null )
127128
else
128129
{
129130
long nextDelay = Math.max( settings.retryTimeoutDelay(), previousDelay * 2 );
130-
logger.info( "Unable to fetch new routing table, will try again in " + nextDelay + "ms" );
131+
log.info( "Unable to fetch new routing table, will try again in " + nextDelay + "ms" );
131132
eventExecutorGroup.next().schedule(
132133
() -> lookupClusterComposition( routingTable, pool, newFailures, nextDelay, result, bookmark, baseError ),
133134
nextDelay, TimeUnit.MILLISECONDS
@@ -291,8 +292,8 @@ private ClusterComposition handleRoutingProcedureError( Throwable error, Routing
291292
DiscoveryException discoveryError = new DiscoveryException( format( RECOVERABLE_ROUTING_ERROR, routerAddress ), error );
292293
Futures.combineErrors( baseError, discoveryError ); // we record each failure here
293294
String warningMessage = format( RECOVERABLE_DISCOVERY_ERROR_WITH_SERVER, routerAddress );
294-
logger.warn( warningMessage );
295-
logger.debug( warningMessage, discoveryError );
295+
log.warn( warningMessage );
296+
log.debug( warningMessage, discoveryError );
296297
routingTable.forget( routerAddress );
297298
return null;
298299
}

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: 13 additions & 12 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;
@@ -36,18 +37,18 @@ public class RoutingTableRegistryImpl implements RoutingTableRegistry
3637
{
3738
private final ConcurrentMap<DatabaseName,RoutingTableHandler> routingTableHandlers;
3839
private final RoutingTableHandlerFactory factory;
39-
private final Logger logger;
40+
private final Logger log;
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.log = logging.getLog( getClass() );
5152
}
5253

5354
@Override
@@ -74,7 +75,7 @@ public Set<BoltServerAddress> allServers()
7475
public void remove( DatabaseName databaseName )
7576
{
7677
routingTableHandlers.remove( databaseName );
77-
logger.debug( "Routing table handler for database '%s' is removed.", databaseName.description() );
78+
log.debug( "Routing table handler for database '%s' is removed.", databaseName.description() );
7879
}
7980

8081
@Override
@@ -85,7 +86,7 @@ public void removeAged()
8586
{
8687
if ( handler.isRoutingTableAged() )
8788
{
88-
logger.info(
89+
log.info(
8990
"Routing table handler for database '%s' is removed because it has not been used for a long time. Routing table: %s",
9091
databaseName.description(), handler.routingTable() );
9192
routingTableHandlers.remove( databaseName );
@@ -111,7 +112,7 @@ private RoutingTableHandler getOrCreate( DatabaseName databaseName )
111112
databaseName, name ->
112113
{
113114
RoutingTableHandler handler = factory.newInstance( name, this );
114-
logger.debug( "Routing table handler for database '%s' is added.", databaseName.description() );
115+
log.debug( "Routing table handler for database '%s' is added.", databaseName.description() );
115116
return handler;
116117
} );
117118
}
@@ -120,23 +121,23 @@ static class RoutingTableHandlerFactory
120121
{
121122
private final ConnectionPool connectionPool;
122123
private final Rediscovery rediscovery;
123-
private final Logger log;
124+
private final Logging logging;
124125
private final Clock clock;
125126
private final long routingTablePurgeDelayMs;
126127

127-
RoutingTableHandlerFactory( ConnectionPool connectionPool, Rediscovery rediscovery, Clock clock, Logger log, long routingTablePurgeDelayMs )
128+
RoutingTableHandlerFactory( ConnectionPool connectionPool, Rediscovery rediscovery, Clock clock, Logging logging, long routingTablePurgeDelayMs )
128129
{
129130
this.connectionPool = connectionPool;
130131
this.rediscovery = rediscovery;
131132
this.clock = clock;
132-
this.log = log;
133+
this.logging = logging;
133134
this.routingTablePurgeDelayMs = routingTablePurgeDelayMs;
134135
}
135136

136137
RoutingTableHandler newInstance( DatabaseName databaseName, RoutingTableRegistry allTables )
137138
{
138139
ClusterRoutingTable routingTable = new ClusterRoutingTable( databaseName, clock );
139-
return new RoutingTableHandlerImpl( routingTable, rediscovery, connectionPool, allTables, log, routingTablePurgeDelayMs );
140+
return new RoutingTableHandlerImpl( routingTable, rediscovery, connectionPool, allTables, logging, routingTablePurgeDelayMs );
140141
}
141142
}
142143
}

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

0 commit comments

Comments
 (0)