Merge "LoggingContext: Remove duplicated comments about copying perf logs between threads"

This commit is contained in:
Edwin Kempin
2020-10-02 10:44:51 +00:00
committed by Gerrit Code Review
3 changed files with 10 additions and 30 deletions

View File

@@ -42,6 +42,15 @@ public class LoggingContext extends com.google.common.flogger.backend.system.Log
private static final ThreadLocal<MutableTags> tags = new ThreadLocal<>();
private static final ThreadLocal<Boolean> forceLogging = new ThreadLocal<>();
private static final ThreadLocal<Boolean> performanceLogging = new ThreadLocal<>();
/**
* When copying the logging context to a new thread we need to ensure that the performance log
* records that are added in the new thread are added to the same {@link
* MutablePerformanceLogRecords} instance (see {@link LoggingContextAwareRunnable} and {@link
* LoggingContextAwareCallable}). This is important since performance log records are processed
* only at the end of the request and performance log records that are created in another thread
* should not get lost.
*/
private static final ThreadLocal<MutablePerformanceLogRecords> performanceLogRecords =
new ThreadLocal<>();
@@ -57,11 +66,6 @@ public class LoggingContext extends com.google.common.flogger.backend.system.Log
return runnable;
}
// Pass the MutablePerformanceLogRecords instance into the LoggingContextAwareRunnable
// constructor so that performance log records that are created in the wrapped runnable are
// added to this MutablePerformanceLogRecords instance. This is important since performance
// log records are processed only at the end of the request and performance log records that
// are created in another thread should not get lost.
return new LoggingContextAwareRunnable(
runnable, getInstance().getMutablePerformanceLogRecords());
}
@@ -71,11 +75,6 @@ public class LoggingContext extends com.google.common.flogger.backend.system.Log
return callable;
}
// Pass the MutablePerformanceLogRecords instance into the LoggingContextAwareCallable
// constructor so that performance log records that are created in the wrapped runnable are
// added to this MutablePerformanceLogRecords instance. This is important since performance
// log records are processed only at the end of the request and performance log records that
// are created in another thread should not get lost.
return new LoggingContextAwareCallable<>(
callable, getInstance().getMutablePerformanceLogRecords());
}
@@ -233,12 +232,7 @@ public class LoggingContext extends com.google.common.flogger.backend.system.Log
* <p><strong>Attention:</strong> The passed in {@link MutablePerformanceLogRecords} instance is
* directly stored in the logging context.
*
* <p>This method is intended to be only used when the logging context is copied to a new thread
* to ensure that the performance log records that are added in the new thread are added to the
* same {@link MutablePerformanceLogRecords} instance (see {@link LoggingContextAwareRunnable} and
* {@link LoggingContextAwareCallable}). This is important since performance log records are
* processed only at the end of the request and performance log records that are created in
* another thread should not get lost.
* <p>This method is intended to be only used when the logging context is copied to a new thread.
*
* @param mutablePerformanceLogRecords the {@link MutablePerformanceLogRecords} instance in which
* performance log records should be stored

View File

@@ -75,13 +75,6 @@ class LoggingContextAwareCallable<T> implements Callable<T> {
loggingCtx.setTags(tags);
loggingCtx.forceLogging(forceLogging);
loggingCtx.performanceLogging(performanceLogging);
// For the performance log records use the {@link MutablePerformanceLogRecords} instance from
// the logging context of the calling thread in the logging context of the new thread. This way
// performance log records that are created from the new thread are available from the logging
// context of the calling thread. This is important since performance log records are processed
// only at the end of the request and performance log records that are created in another thread
// should not get lost.
loggingCtx.setMutablePerformanceLogRecords(mutablePerformanceLogRecords);
try {
return callable.call();

View File

@@ -98,13 +98,6 @@ public class LoggingContextAwareRunnable implements Runnable {
loggingCtx.setTags(tags);
loggingCtx.forceLogging(forceLogging);
loggingCtx.performanceLogging(performanceLogging);
// For the performance log records use the {@link MutablePerformanceLogRecords} instance from
// the logging context of the calling thread in the logging context of the new thread. This way
// performance log records that are created from the new thread are available from the logging
// context of the calling thread. This is important since performance log records are processed
// only at the end of the request and performance log records that are created in another thread
// should not get lost.
loggingCtx.setMutablePerformanceLogRecords(mutablePerformanceLogRecords);
try {
runnable.run();