Skip to content

Commit

Permalink
Merge pull request #113 from Netflix/auto_log_level_switch
Browse files Browse the repository at this point in the history
Automatically switch logs to DEBUG on client wrong key error
  • Loading branch information
smukil authored Apr 29, 2021
2 parents 0d9c971 + 8476ac1 commit d67511c
Showing 1 changed file with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public class EVCacheMemcachedClient extends MemcachedClient {
private Property<Long> mutateOperationTimeout;
private final ConnectionFactory connectionFactory;
private final Property<Integer> maxReadDuration, maxWriteDuration;
private final Property<Boolean> enableDebugLogsOnWrongKey;

public EVCacheMemcachedClient(ConnectionFactory cf, List<InetSocketAddress> addrs,
Property<Integer> readTimeout, EVCacheClient client) throws IOException {
Expand All @@ -86,6 +87,7 @@ public EVCacheMemcachedClient(ConnectionFactory cf, List<InetSocketAddress> addr
this.appName = client.getAppName();
this.maxWriteDuration = EVCacheConfig.getInstance().getPropertyRepository().get(appName + ".max.write.duration.metric", Integer.class).orElseGet("evcache.max.write.duration.metric").orElse(50);
this.maxReadDuration = EVCacheConfig.getInstance().getPropertyRepository().get(appName + ".max.read.duration.metric", Integer.class).orElseGet("evcache.max.read.duration.metric").orElse(20);
this.enableDebugLogsOnWrongKey = EVCacheConfig.getInstance().getPropertyRepository().get(appName + ".enable.debug.logs.on.wrongkey", Boolean.class).orElse(false);
}

public NodeLocator getNodeLocator() {
Expand All @@ -111,6 +113,11 @@ private boolean isWrongKeyReturned(String original_key, String returned_key) {
log.error("Wrong key returned. Key - " + original_key + " (Host: " + original_host + ") ; Returned Key "
+ returned_key + " (Host: " + returned_host + ")", new Exception());
client.reportWrongKeyReturned(original_host);

// If we are configured to dynamically switch log levels to DEBUG on a wrong key error, do so here.
if (enableDebugLogsOnWrongKey.get()) {
System.setProperty("log4j.logger.net.spy.memcached", "DEBUG");
}
return true;
}
return false;
Expand Down

0 comments on commit d67511c

Please sign in to comment.