|
42 | 42 | import com.google.cloud.logging.Synchronicity; |
43 | 43 | import com.google.common.collect.Iterables; |
44 | 44 | import com.google.common.collect.Iterators; |
45 | | -import com.google.errorprone.annotations.concurrent.LazyInit; |
46 | 45 | import com.google.protobuf.Struct; |
47 | 46 | import java.io.BufferedOutputStream; |
48 | 47 | import java.io.File; |
@@ -146,7 +145,7 @@ static ResourceBundle resourceBundleForNonDirectLogLevelHint(Level nonDirectLogL |
146 | 145 | } |
147 | 146 |
|
148 | 147 | /** If true, add SLF4J MDC to custom_data of the log message. */ |
149 | | - @LazyInit private boolean logCustomMdc = false; |
| 148 | + private final AtomicBoolean logCustomMdc = new AtomicBoolean(false); |
150 | 149 |
|
151 | 150 | // Only instantiated and set if enableDirectLogging is called. |
152 | 151 | private static class DirectLoggingState { |
@@ -248,7 +247,7 @@ public DataflowWorkerLoggingHandler(String filename, long sizeLimit) throws IOEx |
248 | 247 | } |
249 | 248 |
|
250 | 249 | public void setLogMdc(boolean enabled) { |
251 | | - logCustomMdc = enabled; |
| 250 | + logCustomMdc.set(enabled); |
252 | 251 | } |
253 | 252 |
|
254 | 253 | private static Pair<ImmutableMap<String, String>, ImmutableMap<String, String>> |
@@ -355,7 +354,7 @@ LogEntry constructDirectLogEntry( |
355 | 354 | addLogField(payloadBuilder, "worker", DataflowWorkerLoggingMDC.getWorkerId(), FIELD_MAX_LENGTH); |
356 | 355 | addLogField(payloadBuilder, "work", DataflowWorkerLoggingMDC.getWorkId(), FIELD_MAX_LENGTH); |
357 | 356 | addLogField(payloadBuilder, "job", DataflowWorkerLoggingMDC.getJobId(), FIELD_MAX_LENGTH); |
358 | | - if (logCustomMdc) { |
| 357 | + if (logCustomMdc.get()) { |
359 | 358 | @Nullable Map<String, String> mdcMap = MDC.getCopyOfContextMap(); |
360 | 359 | if (mdcMap != null && !mdcMap.isEmpty()) { |
361 | 360 | Struct.Builder customDataBuilder = |
@@ -606,7 +605,7 @@ public synchronized void publishToDisk( |
606 | 605 | writeIfNotEmpty(generator, "work", DataflowWorkerLoggingMDC.getWorkId()); |
607 | 606 | writeIfNotEmpty(generator, "logger", record.getLoggerName()); |
608 | 607 | writeIfNotEmpty(generator, "exception", formatException(record.getThrown())); |
609 | | - if (logCustomMdc) { |
| 608 | + if (logCustomMdc.get()) { |
610 | 609 | @Nullable Map<String, String> mdcMap = MDC.getCopyOfContextMap(); |
611 | 610 | if (mdcMap != null && !mdcMap.isEmpty()) { |
612 | 611 | generator.writeFieldName("custom_data"); |
|
0 commit comments