Skip to content

Make Logger instance names qualified #973

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

Merged
merged 1 commit into from
Aug 4, 2021
Merged
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
6 changes: 6 additions & 0 deletions driver/clirr-ignored-differences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,10 @@
<method>void debug(java.lang.String, java.lang.Throwable)</method>
</difference>

<difference>
<className>org/neo4j/driver/Logging</className>
<differenceType>7012</differenceType>
<method>org.neo4j.driver.Logger getLog(java.lang.Class)</method>
</difference>

</differences>
4 changes: 1 addition & 3 deletions driver/src/main/java/org/neo4j/driver/GraphDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
*/
public class GraphDatabase
{
private static final String LOGGER_NAME = GraphDatabase.class.getSimpleName();

/**
* Return a driver for a Neo4j instance with the default configuration settings
*
Expand Down Expand Up @@ -206,7 +204,7 @@ private static void assertRoutingUris( Iterable<URI> uris )
private static Logger createLogger( Config config )
{
Logging logging = getOrDefault( config ).logging();
return logging.getLog( LOGGER_NAME );
return logging.getLog( GraphDatabase.class );
}

private static Config getOrDefault( Config config )
Expand Down
12 changes: 12 additions & 0 deletions driver/src/main/java/org/neo4j/driver/Logging.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,18 @@
*/
public interface Logging
{
/**
* Obtain a {@link Logger} instance by class, its name will be the fully qualified name of the class.
*
* @param clazz class whose name should be used as the {@link Logger} name.
* @return {@link Logger} instance
*/
default Logger getLog( Class<?> clazz )
{
String canonicalName = clazz.getCanonicalName();
return getLog( canonicalName != null ? canonicalName : clazz.getName() );
}

/**
* Obtain a {@link Logger} instance by name.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ protected InternalDriver createDirectDriver( SecurityPlan securityPlan, BoltServ
ConnectionProvider connectionProvider = new DirectConnectionProvider( address, connectionPool );
SessionFactory sessionFactory = createSessionFactory( connectionProvider, retryLogic, config );
InternalDriver driver = createDriver( securityPlan, sessionFactory, metricsProvider, config );
Logger log = config.logging().getLog( Driver.class.getSimpleName() );
Logger log = config.logging().getLog( getClass() );
log.info( "Direct driver instance %s created for server address %s", driver.hashCode(), address );
return driver;
}
Expand All @@ -186,7 +186,7 @@ protected InternalDriver createRoutingDriver( SecurityPlan securityPlan, BoltSer
config, routingSettings );
SessionFactory sessionFactory = createSessionFactory( connectionProvider, retryLogic, config );
InternalDriver driver = createDriver( securityPlan, sessionFactory, metricsProvider, config );
Logger log = config.logging().getLog( Driver.class.getSimpleName() );
Logger log = config.logging().getLog( getClass() );
log.info( "Routing driver instance %s created for server address %s", driver.hashCode(), address );
return driver;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class InternalDriver implements Driver
this.securityPlan = securityPlan;
this.sessionFactory = sessionFactory;
this.metricsProvider = metricsProvider;
this.log = logging.getLog( Driver.class.getSimpleName() );
this.log = logging.getLog( getClass() );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ private void logLeakIfNeeded()
Boolean isOpen = Futures.blockingGet( currentConnectionIsOpen() );
if ( isOpen )
{
logger.error( "Neo4j Session object leaked, please ensure that your application " +
"fully consumes results in Sessions or explicitly calls `close` on Sessions before disposing of the objects.\n" +
"Session was create at:\n" + stackTrace, null );
log.error( "Neo4j Session object leaked, please ensure that your application " +
"fully consumes results in Sessions or explicitly calls `close` on Sessions before disposing of the objects.\n" +
"Session was create at:\n" + stackTrace, null );
}
}
private static String captureStackTrace()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public class NetworkConnection implements Connection

public NetworkConnection( Channel channel, ExtendedChannelPool channelPool, Clock clock, MetricsListener metricsListener, Logging logging )
{
this.log = logging.getLog( this.getClass().getCanonicalName() );
this.log = logging.getLog( getClass() );
this.channel = channel;
this.messageDispatcher = ChannelAttributes.messageDispatcher( channel );
this.serverAgent = ChannelAttributes.serverAgent( channel );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,11 @@

public class NetworkSession
{
private static final String LOG_NAME = "Session";

private final ConnectionProvider connectionProvider;
private final NetworkSessionConnectionContext connectionContext;
private final AccessMode mode;
private final RetryLogic retryLogic;
protected final Logger logger;
protected final Logger log;

private final BookmarkHolder bookmarkHolder;
private final long fetchSize;
Expand All @@ -70,7 +68,7 @@ public NetworkSession( ConnectionProvider connectionProvider, RetryLogic retryLo
this.connectionProvider = connectionProvider;
this.mode = mode;
this.retryLogic = retryLogic;
this.logger = new PrefixedLogger( "[" + hashCode() + "]", logging.getLog( LOG_NAME ) );
this.log = new PrefixedLogger( "[" + hashCode() + "]", logging.getLog( getClass() ) );
this.bookmarkHolder = bookmarkHolder;
this.connectionContext = new NetworkSessionConnectionContext( databaseName, bookmarkHolder.getBookmark() );
this.fetchSize = fetchSize;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ protected ConnectionPoolImpl( ChannelConnector connector, Bootstrap bootstrap, N
this.channelHealthChecker = nettyChannelHealthChecker;
this.settings = settings;
this.metricsListener = metricsListener;
this.log = logging.getLog( ConnectionPool.class.getSimpleName() );
this.log = logging.getLog( getClass() );
this.ownsEventLoopGroup = ownsEventLoopGroup;
this.connectionFactory = connectionFactory;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,16 @@ public class NettyChannelHealthChecker implements ChannelHealthChecker, Authoriz
{
private final PoolSettings poolSettings;
private final Clock clock;
private final Logging logging;
private final Logger log;
private final AtomicReference<Optional<Long>> minCreationTimestampMillisOpt;

public NettyChannelHealthChecker( PoolSettings poolSettings, Clock clock, Logging logging )
{
this.poolSettings = poolSettings;
this.clock = clock;
this.log = logging.getLog( getClass().getSimpleName() );
this.logging = logging;
this.log = logging.getLog( getClass() );
this.minCreationTimestampMillisOpt = new AtomicReference<>( Optional.empty() );
}

Expand Down Expand Up @@ -129,7 +131,7 @@ private boolean hasBeenIdleForTooLong( Channel channel )
private Future<Boolean> ping( Channel channel )
{
Promise<Boolean> result = channel.eventLoop().newPromise();
messageDispatcher( channel ).enqueue( new PingResponseHandler( result, channel, log ) );
messageDispatcher( channel ).enqueue( new PingResponseHandler( result, channel, logging ) );
channel.writeAndFlush( ResetMessage.RESET, channel.voidPromise() );
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public NettyChannelTracker( MetricsListener metricsListener, EventExecutor event
public NettyChannelTracker( MetricsListener metricsListener, ChannelGroup channels, Logging logging )
{
this.metricsListener = metricsListener;
this.log = logging.getLog( getClass().getSimpleName() );
this.log = logging.getLog( getClass() );
this.allChannels = channels;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

import org.neo4j.driver.Bookmark;
import org.neo4j.driver.Logger;
import org.neo4j.driver.Logging;
import org.neo4j.driver.exceptions.DiscoveryException;
import org.neo4j.driver.exceptions.FatalDiscoveryException;
import org.neo4j.driver.exceptions.SecurityException;
Expand Down Expand Up @@ -62,18 +63,18 @@ public class RediscoveryImpl implements Rediscovery

private final BoltServerAddress initialRouter;
private final RoutingSettings settings;
private final Logger logger;
private final Logger log;
private final ClusterCompositionProvider provider;
private final ServerAddressResolver resolver;
private final EventExecutorGroup eventExecutorGroup;
private final DomainNameResolver domainNameResolver;

public RediscoveryImpl( BoltServerAddress initialRouter, RoutingSettings settings, ClusterCompositionProvider provider,
EventExecutorGroup eventExecutorGroup, ServerAddressResolver resolver, Logger logger, DomainNameResolver domainNameResolver )
EventExecutorGroup eventExecutorGroup, ServerAddressResolver resolver, Logging logging, DomainNameResolver domainNameResolver )
{
this.initialRouter = initialRouter;
this.settings = settings;
this.logger = logger;
this.log = logging.getLog( getClass() );
this.provider = provider;
this.resolver = resolver;
this.eventExecutorGroup = eventExecutorGroup;
Expand Down Expand Up @@ -127,7 +128,7 @@ else if ( compositionLookupResult != null )
else
{
long nextDelay = Math.max( settings.retryTimeoutDelay(), previousDelay * 2 );
logger.info( "Unable to fetch new routing table, will try again in " + nextDelay + "ms" );
log.info( "Unable to fetch new routing table, will try again in " + nextDelay + "ms" );
eventExecutorGroup.next().schedule(
() -> lookupClusterComposition( routingTable, pool, newFailures, nextDelay, result, bookmark, baseError ),
nextDelay, TimeUnit.MILLISECONDS
Expand Down Expand Up @@ -291,8 +292,8 @@ private ClusterComposition handleRoutingProcedureError( Throwable error, Routing
DiscoveryException discoveryError = new DiscoveryException( format( RECOVERABLE_ROUTING_ERROR, routerAddress ), error );
Futures.combineErrors( baseError, discoveryError ); // we record each failure here
String warningMessage = format( RECOVERABLE_DISCOVERY_ERROR_WITH_SERVER, routerAddress );
logger.warn( warningMessage );
logger.debug( warningMessage, discoveryError );
log.warn( warningMessage );
log.debug( warningMessage, discoveryError );
routingTable.forget( routerAddress );
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.concurrent.CompletionStage;

import org.neo4j.driver.Logger;
import org.neo4j.driver.Logging;
import org.neo4j.driver.internal.BoltServerAddress;
import org.neo4j.driver.internal.DatabaseName;
import org.neo4j.driver.internal.async.ConnectionContext;
Expand All @@ -45,15 +46,16 @@ public class RoutingTableHandlerImpl implements RoutingTableHandler
private final long routingTablePurgeDelayMs;
private final Set<BoltServerAddress> resolvedInitialRouters = new HashSet<>();

public RoutingTableHandlerImpl( RoutingTable routingTable, Rediscovery rediscovery, ConnectionPool connectionPool, RoutingTableRegistry routingTableRegistry,
Logger log, long routingTablePurgeDelayMs )
public RoutingTableHandlerImpl( RoutingTable routingTable, Rediscovery rediscovery, ConnectionPool connectionPool,
RoutingTableRegistry routingTableRegistry,
Logging logging, long routingTablePurgeDelayMs )
{
this.routingTable = routingTable;
this.databaseName = routingTable.database();
this.rediscovery = rediscovery;
this.connectionPool = connectionPool;
this.routingTableRegistry = routingTableRegistry;
this.log = log;
this.log = logging.getLog( getClass() );
this.routingTablePurgeDelayMs = routingTablePurgeDelayMs;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.concurrent.ConcurrentMap;

import org.neo4j.driver.Logger;
import org.neo4j.driver.Logging;
import org.neo4j.driver.internal.BoltServerAddress;
import org.neo4j.driver.internal.DatabaseName;
import org.neo4j.driver.internal.async.ConnectionContext;
Expand All @@ -36,18 +37,18 @@ public class RoutingTableRegistryImpl implements RoutingTableRegistry
{
private final ConcurrentMap<DatabaseName,RoutingTableHandler> routingTableHandlers;
private final RoutingTableHandlerFactory factory;
private final Logger logger;
private final Logger log;

public RoutingTableRegistryImpl( ConnectionPool connectionPool, Rediscovery rediscovery, Clock clock, Logger logger, long routingTablePurgeDelayMs )
public RoutingTableRegistryImpl( ConnectionPool connectionPool, Rediscovery rediscovery, Clock clock, Logging logging, long routingTablePurgeDelayMs )
{
this( new ConcurrentHashMap<>(), new RoutingTableHandlerFactory( connectionPool, rediscovery, clock, logger, routingTablePurgeDelayMs ), logger );
this( new ConcurrentHashMap<>(), new RoutingTableHandlerFactory( connectionPool, rediscovery, clock, logging, routingTablePurgeDelayMs ), logging );
}

RoutingTableRegistryImpl( ConcurrentMap<DatabaseName,RoutingTableHandler> routingTableHandlers, RoutingTableHandlerFactory factory, Logger logger )
RoutingTableRegistryImpl( ConcurrentMap<DatabaseName,RoutingTableHandler> routingTableHandlers, RoutingTableHandlerFactory factory, Logging logging )
{
this.factory = factory;
this.routingTableHandlers = routingTableHandlers;
this.logger = logger;
this.log = logging.getLog( getClass() );
}

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

@Override
Expand All @@ -85,7 +86,7 @@ public void removeAged()
{
if ( handler.isRoutingTableAged() )
{
logger.info(
log.info(
"Routing table handler for database '%s' is removed because it has not been used for a long time. Routing table: %s",
databaseName.description(), handler.routingTable() );
routingTableHandlers.remove( databaseName );
Expand All @@ -111,7 +112,7 @@ private RoutingTableHandler getOrCreate( DatabaseName databaseName )
databaseName, name ->
{
RoutingTableHandler handler = factory.newInstance( name, this );
logger.debug( "Routing table handler for database '%s' is added.", databaseName.description() );
log.debug( "Routing table handler for database '%s' is added.", databaseName.description() );
return handler;
} );
}
Expand All @@ -120,23 +121,23 @@ static class RoutingTableHandlerFactory
{
private final ConnectionPool connectionPool;
private final Rediscovery rediscovery;
private final Logger log;
private final Logging logging;
private final Clock clock;
private final long routingTablePurgeDelayMs;

RoutingTableHandlerFactory( ConnectionPool connectionPool, Rediscovery rediscovery, Clock clock, Logger log, long routingTablePurgeDelayMs )
RoutingTableHandlerFactory( ConnectionPool connectionPool, Rediscovery rediscovery, Clock clock, Logging logging, long routingTablePurgeDelayMs )
{
this.connectionPool = connectionPool;
this.rediscovery = rediscovery;
this.clock = clock;
this.log = log;
this.logging = logging;
this.routingTablePurgeDelayMs = routingTablePurgeDelayMs;
}

RoutingTableHandler newInstance( DatabaseName databaseName, RoutingTableRegistry allTables )
{
ClusterRoutingTable routingTable = new ClusterRoutingTable( databaseName, clock );
return new RoutingTableHandlerImpl( routingTable, rediscovery, connectionPool, allTables, log, routingTablePurgeDelayMs );
return new RoutingTableHandlerImpl( routingTable, rediscovery, connectionPool, allTables, logging, routingTablePurgeDelayMs );
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
*/
package org.neo4j.driver.internal.cluster.loadbalancing;

import org.neo4j.driver.internal.BoltServerAddress;
import org.neo4j.driver.internal.spi.ConnectionPool;
import org.neo4j.driver.Logger;
import org.neo4j.driver.Logging;
import org.neo4j.driver.internal.BoltServerAddress;
import org.neo4j.driver.internal.spi.ConnectionPool;

/**
* Load balancing strategy that finds server with least amount of active (checked out of the pool) connections from
Expand All @@ -30,8 +30,6 @@
*/
public class LeastConnectedLoadBalancingStrategy implements LoadBalancingStrategy
{
private static final String LOGGER_NAME = LeastConnectedLoadBalancingStrategy.class.getSimpleName();

private final RoundRobinArrayIndex readersIndex = new RoundRobinArrayIndex();
private final RoundRobinArrayIndex writersIndex = new RoundRobinArrayIndex();

Expand All @@ -41,7 +39,7 @@ public class LeastConnectedLoadBalancingStrategy implements LoadBalancingStrateg
public LeastConnectedLoadBalancingStrategy( ConnectionPool connectionPool, Logging logging )
{
this.connectionPool = connectionPool;
this.log = logging.getLog( LOGGER_NAME );
this.log = logging.getLog( getClass() );
}

@Override
Expand Down
Loading