To add a {@code LoggingHandler} to an existing {@link Logger} and be sure to avoid infinite @@ -118,6 +129,8 @@ *
* {@code com.example.mypackage.handlers=com.google.cloud.logging.LoggingHandler} *+ * + * @see Structured logging */ public class LoggingHandler extends Handler { @@ -139,6 +152,9 @@ public class LoggingHandler extends Handler { private volatile Level flushLevel; + private volatile Boolean autoPopulateMetadata; + private volatile Boolean redirectToStdout; + private WriteOption[] defaultWriteOptions; /** Creates an handler that publishes messages to Cloud Logging. */ @@ -196,7 +212,10 @@ public LoggingHandler( } /** - * Creates a handler that publishes messages to Cloud Logging. + * Creates a handler that publishes messages to Cloud Logging. Auto-population of the logs + * metadata can be opted-out in {@code options} argument or in the configuration file. At least + * one flag {@link LoggingOptions} or {@link LoggingConfig} has to be explicitly set to {@code + * false} in order to opt-out the metadata auto-population. * * @param log the name of the log to which log entries are written * @param options options for the Cloud Logging service @@ -222,14 +241,19 @@ public LoggingHandler( setLevel(level); baseLevel = level.equals(Level.ALL) ? Level.FINEST : level; flushLevel = config.getFlushLevel(); + Boolean f1 = options.getAutoPopulateMetadata(); + Boolean f2 = config.getAutoPopulateMetadata(); + autoPopulateMetadata = isTrueOrNull(f1) && isTrueOrNull(f2); + redirectToStdout = firstNonNull(config.getRedirectToStdout(), Boolean.FALSE); String logName = log != null ? log : config.getLogName(); - MonitoredResource resource = firstNonNull( monitoredResource, config.getMonitoredResource(loggingOptions.getProjectId())); List