Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import com.google.cloud.logging.Synchronicity;
import com.google.common.collect.Iterables;
import com.google.common.collect.Iterators;
import com.google.errorprone.annotations.concurrent.LazyInit;
import com.google.protobuf.Struct;
import java.io.BufferedOutputStream;
import java.io.File;
Expand Down Expand Up @@ -146,7 +145,7 @@ static ResourceBundle resourceBundleForNonDirectLogLevelHint(Level nonDirectLogL
}

/** If true, add SLF4J MDC to custom_data of the log message. */
@LazyInit private boolean logCustomMdc = false;
private final AtomicBoolean logCustomMdc = new AtomicBoolean(false);

// Only instantiated and set if enableDirectLogging is called.
private static class DirectLoggingState {
Expand Down Expand Up @@ -248,7 +247,7 @@ public DataflowWorkerLoggingHandler(String filename, long sizeLimit) throws IOEx
}

public void setLogMdc(boolean enabled) {
logCustomMdc = enabled;
logCustomMdc.set(enabled);
}

private static Pair<ImmutableMap<String, String>, ImmutableMap<String, String>>
Expand Down Expand Up @@ -355,7 +354,7 @@ LogEntry constructDirectLogEntry(
addLogField(payloadBuilder, "worker", DataflowWorkerLoggingMDC.getWorkerId(), FIELD_MAX_LENGTH);
addLogField(payloadBuilder, "work", DataflowWorkerLoggingMDC.getWorkId(), FIELD_MAX_LENGTH);
addLogField(payloadBuilder, "job", DataflowWorkerLoggingMDC.getJobId(), FIELD_MAX_LENGTH);
if (logCustomMdc) {
if (logCustomMdc.get()) {
@Nullable Map<String, String> mdcMap = MDC.getCopyOfContextMap();
if (mdcMap != null && !mdcMap.isEmpty()) {
Struct.Builder customDataBuilder =
Expand Down Expand Up @@ -606,7 +605,7 @@ public synchronized void publishToDisk(
writeIfNotEmpty(generator, "work", DataflowWorkerLoggingMDC.getWorkId());
writeIfNotEmpty(generator, "logger", record.getLoggerName());
writeIfNotEmpty(generator, "exception", formatException(record.getThrown()));
if (logCustomMdc) {
if (logCustomMdc.get()) {
@Nullable Map<String, String> mdcMap = MDC.getCopyOfContextMap();
if (mdcMap != null && !mdcMap.isEmpty()) {
generator.writeFieldName("custom_data");
Expand Down
Loading