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
}

0 commit comments

Comments
 (0)