By default {@code Logging} will also create keys for:
*
*
- *
coldStart - True if this is the first invocation of this Lambda execution environment; else False
+ *
cold_start - True if this is the first invocation of this Lambda execution environment; else False
*
service - The value of the 'POWER_TOOLS_SERVICE_NAME' environment variable or 'service_undefined'
- *
samplingRate - The value of the 'POWERTOOLS_LOGGER_SAMPLE_RATE' environment variable or value of samplingRate field or 0.
+ *
sampling_rate - The value of the 'POWERTOOLS_LOGGER_SAMPLE_RATE' environment variable or value of sampling_rate field or 0.
* Valid value is from 0.0 to 1.0. Value outside this range is silently ignored.
*
*
diff --git a/powertools-logging/src/main/java/software/amazon/lambda/powertools/logging/LoggingUtils.java b/powertools-logging/src/main/java/software/amazon/lambda/powertools/logging/LoggingUtils.java
index f23e274d4..b90572fb6 100644
--- a/powertools-logging/src/main/java/software/amazon/lambda/powertools/logging/LoggingUtils.java
+++ b/powertools-logging/src/main/java/software/amazon/lambda/powertools/logging/LoggingUtils.java
@@ -13,12 +13,11 @@
*/
package software.amazon.lambda.powertools.logging;
-import java.util.Map;
-
import com.fasterxml.jackson.databind.ObjectMapper;
-import org.apache.logging.log4j.ThreadContext;
+import org.slf4j.MDC;
-import static java.util.Arrays.asList;
+import java.util.Arrays;
+import java.util.Map;
/**
* A class of helper functions to add additional functionality to Logging.
@@ -39,7 +38,7 @@ private LoggingUtils() {
* @param value The value to be logged
*/
public static void appendKey(String key, String value) {
- ThreadContext.put(key, value);
+ MDC.put(key, value);
}
@@ -51,7 +50,7 @@ public static void appendKey(String key, String value) {
* @param customKeys Map of custom keys values to be appended to logs
*/
public static void appendKeys(Map customKeys) {
- ThreadContext.putAll(customKeys);
+ customKeys.forEach(MDC::put);
}
/**
@@ -60,7 +59,7 @@ public static void appendKeys(Map customKeys) {
* @param customKey The name of the key to be logged
*/
public static void removeKey(String customKey) {
- ThreadContext.remove(customKey);
+ MDC.remove(customKey);
}
@@ -70,7 +69,7 @@ public static void removeKey(String customKey) {
* @param keys Map of custom keys values to be appended to logs
*/
public static void removeKeys(String... keys) {
- ThreadContext.removeAll(asList(keys));
+ Arrays.stream(keys).forEach(MDC::remove);
}
/**
@@ -79,7 +78,7 @@ public static void removeKeys(String... keys) {
* @param value The value of the correlation id
*/
public static void setCorrelationId(String value) {
- ThreadContext.put("correlation_id", value);
+ MDC.put("correlation_id", value);
}
/**
diff --git a/powertools-logging/src/main/java/software/amazon/lambda/powertools/logging/internal/AbstractJacksonLayoutCopy.java b/powertools-logging/src/main/java/software/amazon/lambda/powertools/logging/internal/AbstractJacksonLayoutCopy.java
deleted file mode 100644
index 3ceda4b79..000000000
--- a/powertools-logging/src/main/java/software/amazon/lambda/powertools/logging/internal/AbstractJacksonLayoutCopy.java
+++ /dev/null
@@ -1,494 +0,0 @@
-package software.amazon.lambda.powertools.logging.internal;
-
-import java.io.IOException;
-import java.io.Writer;
-import java.nio.charset.Charset;
-import java.util.LinkedHashMap;
-import java.util.Map;
-
-import org.apache.logging.log4j.Level;
-import org.apache.logging.log4j.Marker;
-import org.apache.logging.log4j.ThreadContext;
-import org.apache.logging.log4j.core.LogEvent;
-import org.apache.logging.log4j.core.config.Configuration;
-import org.apache.logging.log4j.core.config.plugins.PluginBuilderAttribute;
-import org.apache.logging.log4j.core.config.plugins.PluginElement;
-import org.apache.logging.log4j.core.impl.Log4jLogEvent;
-import org.apache.logging.log4j.core.impl.ThrowableProxy;
-import org.apache.logging.log4j.core.jackson.XmlConstants;
-import org.apache.logging.log4j.core.layout.AbstractStringLayout;
-import org.apache.logging.log4j.core.lookup.StrSubstitutor;
-import org.apache.logging.log4j.core.time.Instant;
-import org.apache.logging.log4j.core.util.KeyValuePair;
-import org.apache.logging.log4j.core.util.StringBuilderWriter;
-import org.apache.logging.log4j.message.Message;
-import org.apache.logging.log4j.util.ReadOnlyStringMap;
-import org.apache.logging.log4j.util.Strings;
-
-import com.fasterxml.jackson.annotation.JsonAnyGetter;
-import com.fasterxml.jackson.annotation.JsonIgnore;
-import com.fasterxml.jackson.annotation.JsonRootName;
-import com.fasterxml.jackson.annotation.JsonUnwrapped;
-import com.fasterxml.jackson.core.JsonGenerationException;
-import com.fasterxml.jackson.databind.JsonMappingException;
-import com.fasterxml.jackson.databind.ObjectWriter;
-
-@Deprecated
-abstract class AbstractJacksonLayoutCopy extends AbstractStringLayout {
-
- protected static final String DEFAULT_EOL = "\r\n";
- protected static final String COMPACT_EOL = Strings.EMPTY;
-
- public static abstract class Builder> extends AbstractStringLayout.Builder {
-
- @PluginBuilderAttribute
- private boolean eventEol;
-
- @PluginBuilderAttribute
- private String endOfLine;
-
- @PluginBuilderAttribute
- private boolean compact;
-
- @PluginBuilderAttribute
- private boolean complete;
-
- @PluginBuilderAttribute
- private boolean locationInfo;
-
- @PluginBuilderAttribute
- private boolean properties;
-
- @PluginBuilderAttribute
- private boolean includeStacktrace = true;
-
- @PluginBuilderAttribute
- private boolean stacktraceAsString = false;
-
- @PluginBuilderAttribute
- private boolean includeNullDelimiter = false;
-
- @PluginBuilderAttribute
- private boolean includeTimeMillis = false;
-
- @PluginElement("AdditionalField")
- private KeyValuePair[] additionalFields;
-
- protected String toStringOrNull(final byte[] header) {
- return header == null ? null : new String(header, Charset.defaultCharset());
- }
-
- public boolean getEventEol() {
- return eventEol;
- }
-
- public String getEndOfLine() {
- return endOfLine;
- }
-
- public boolean isCompact() {
- return compact;
- }
-
- public boolean isComplete() {
- return complete;
- }
-
- public boolean isLocationInfo() {
- return locationInfo;
- }
-
- public boolean isProperties() {
- return properties;
- }
-
- /**
- * If "true", includes the stacktrace of any Throwable in the generated data, defaults to "true".
- * @return If "true", includes the stacktrace of any Throwable in the generated data, defaults to "true".
- */
- public boolean isIncludeStacktrace() {
- return includeStacktrace;
- }
-
- public boolean isStacktraceAsString() {
- return stacktraceAsString;
- }
-
- public boolean isIncludeNullDelimiter() { return includeNullDelimiter; }
-
- public boolean isIncludeTimeMillis() {
- return includeTimeMillis;
- }
-
- public KeyValuePair[] getAdditionalFields() {
- return additionalFields;
- }
-
- public B setEventEol(final boolean eventEol) {
- this.eventEol = eventEol;
- return asBuilder();
- }
-
- public B setEndOfLine(final String endOfLine) {
- this.endOfLine = endOfLine;
- return asBuilder();
- }
-
- public B setCompact(final boolean compact) {
- this.compact = compact;
- return asBuilder();
- }
-
- public B setComplete(final boolean complete) {
- this.complete = complete;
- return asBuilder();
- }
-
- public B setLocationInfo(final boolean locationInfo) {
- this.locationInfo = locationInfo;
- return asBuilder();
- }
-
- public B setProperties(final boolean properties) {
- this.properties = properties;
- return asBuilder();
- }
-
- /**
- * If "true", includes the stacktrace of any Throwable in the generated JSON, defaults to "true".
- * @param includeStacktrace If "true", includes the stacktrace of any Throwable in the generated JSON, defaults to "true".
- * @return this builder
- */
- public B setIncludeStacktrace(final boolean includeStacktrace) {
- this.includeStacktrace = includeStacktrace;
- return asBuilder();
- }
-
- /**
- * Whether to format the stacktrace as a string, and not a nested object (optional, defaults to false).
- *
- * @return this builder
- */
- public B setStacktraceAsString(final boolean stacktraceAsString) {
- this.stacktraceAsString = stacktraceAsString;
- return asBuilder();
- }
-
- /**
- * Whether to include NULL byte as delimiter after each event (optional, default to false).
- *
- * @return this builder
- */
- public B setIncludeNullDelimiter(final boolean includeNullDelimiter) {
- this.includeNullDelimiter = includeNullDelimiter;
- return asBuilder();
- }
-
- /**
- * Whether to include the timestamp (in addition to the Instant) (optional, default to false).
- *
- * @return this builder
- */
- public B setIncludeTimeMillis(final boolean includeTimeMillis) {
- this.includeTimeMillis = includeTimeMillis;
- return asBuilder();
- }
-
- /**
- * Additional fields to set on each log event.
- *
- * @return this builder
- */
- public B setAdditionalFields(final KeyValuePair[] additionalFields) {
- this.additionalFields = additionalFields;
- return asBuilder();
- }
- }
-
- protected final String eol;
- protected final ObjectWriter objectWriter;
- protected final boolean compact;
- protected final boolean complete;
- protected final boolean includeNullDelimiter;
- protected final ResolvableKeyValuePair[] additionalFields;
-
- @Deprecated
- protected AbstractJacksonLayoutCopy(final Configuration config, final ObjectWriter objectWriter, final Charset charset,
- final boolean compact, final boolean complete, final boolean eventEol, final Serializer headerSerializer,
- final Serializer footerSerializer) {
- this(config, objectWriter, charset, compact, complete, eventEol, headerSerializer, footerSerializer, false);
- }
-
- @Deprecated
- protected AbstractJacksonLayoutCopy(final Configuration config, final ObjectWriter objectWriter, final Charset charset,
- final boolean compact, final boolean complete, final boolean eventEol, final Serializer headerSerializer,
- final Serializer footerSerializer, final boolean includeNullDelimiter) {
- this(config, objectWriter, charset, compact, complete, eventEol, null, headerSerializer, footerSerializer, includeNullDelimiter, null);
- }
-
- protected AbstractJacksonLayoutCopy(final Configuration config, final ObjectWriter objectWriter, final Charset charset,
- final boolean compact, final boolean complete, final boolean eventEol, final String endOfLine, final Serializer headerSerializer,
- final Serializer footerSerializer, final boolean includeNullDelimiter,
- final KeyValuePair[] additionalFields) {
- super(config, charset, headerSerializer, footerSerializer);
- this.objectWriter = objectWriter;
- this.compact = compact;
- this.complete = complete;
- this.eol = endOfLine != null ? endOfLine : compact && !eventEol ? COMPACT_EOL : DEFAULT_EOL;
- this.includeNullDelimiter = includeNullDelimiter;
- this.additionalFields = prepareAdditionalFields(config, additionalFields);
- }
-
- protected static boolean valueNeedsLookup(final String value) {
- return value != null && value.contains("${");
- }
-
- private static ResolvableKeyValuePair[] prepareAdditionalFields(final Configuration config, final KeyValuePair[] additionalFields) {
- if (additionalFields == null || additionalFields.length == 0) {
- // No fields set
- return ResolvableKeyValuePair.EMPTY_ARRAY;
- }
-
- // Convert to specific class which already determines whether values needs lookup during serialization
- final ResolvableKeyValuePair[] resolvableFields = new ResolvableKeyValuePair[additionalFields.length];
-
- for (int i = 0; i < additionalFields.length; i++) {
- final ResolvableKeyValuePair resolvable = resolvableFields[i] = new ResolvableKeyValuePair(additionalFields[i]);
-
- // Validate
- if (config == null && resolvable.valueNeedsLookup) {
- throw new IllegalArgumentException("configuration needs to be set when there are additional fields with variables");
- }
- }
-
- return resolvableFields;
- }
-
- /**
- * Formats a {@link org.apache.logging.log4j.core.LogEvent}.
- *
- * @param event The LogEvent.
- * @return The XML representation of the LogEvent.
- */
- @Override
- public String toSerializable(final LogEvent event) {
- final StringBuilderWriter writer = new StringBuilderWriter();
- try {
- toSerializable(event, writer);
- return writer.toString();
- } catch (final IOException e) {
- // Should this be an ISE or IAE?
- LOGGER.error(e);
- return Strings.EMPTY;
- }
- }
-
- private static LogEvent convertMutableToLog4jEvent(final LogEvent event) {
- return event instanceof Log4jLogEvent ? event : Log4jLogEvent.createMemento(event);
- }
-
- protected Object wrapLogEvent(final LogEvent event) {
- if (additionalFields.length > 0) {
- // Construct map for serialization - note that we are intentionally using original LogEvent
- final Map additionalFieldsMap = resolveAdditionalFields(event);
- // This class combines LogEvent with AdditionalFields during serialization
- return new LogEventWithAdditionalFields(event, additionalFieldsMap);
- } else if (event instanceof Message) {
- // If the LogEvent implements the Messagee interface Jackson will not treat is as a LogEvent.
- return new ReadOnlyLogEventWrapper(event);
- } else {
- // No additional fields, return original object
- return event;
- }
- }
-
- private Map resolveAdditionalFields(final LogEvent logEvent) {
- // Note: LinkedHashMap retains order
- final Map additionalFieldsMap = new LinkedHashMap<>(additionalFields.length);
- final StrSubstitutor strSubstitutor = configuration.getStrSubstitutor();
-
- // Go over each field
- for (final ResolvableKeyValuePair pair : additionalFields) {
- if (pair.valueNeedsLookup) {
- // Resolve value
- additionalFieldsMap.put(pair.key, strSubstitutor.replace(logEvent, pair.value));
- } else {
- // Plain text value
- additionalFieldsMap.put(pair.key, pair.value);
- }
- }
-
- return additionalFieldsMap;
- }
-
- public void toSerializable(final LogEvent event, final Writer writer)
- throws JsonGenerationException, JsonMappingException, IOException {
- objectWriter.writeValue(writer, wrapLogEvent(convertMutableToLog4jEvent(event)));
- writer.write(eol);
- if (includeNullDelimiter) {
- writer.write('\0');
- }
- markEvent();
- }
-
- @JsonRootName(XmlConstants.ELT_EVENT)
- public static class LogEventWithAdditionalFields {
-
- private final Object logEvent;
- private final Map additionalFields;
-
- public LogEventWithAdditionalFields(final Object logEvent, final Map additionalFields) {
- this.logEvent = logEvent;
- this.additionalFields = additionalFields;
- }
-
- @JsonUnwrapped
- public Object getLogEvent() {
- return logEvent;
- }
-
- @JsonAnyGetter
- @SuppressWarnings("unused")
- public Map getAdditionalFields() {
- return additionalFields;
- }
- }
-
- protected static class ResolvableKeyValuePair {
-
- /**
- * The empty array.
- */
- static final ResolvableKeyValuePair[] EMPTY_ARRAY = {};
-
- final String key;
- final String value;
- final boolean valueNeedsLookup;
-
- ResolvableKeyValuePair(final KeyValuePair pair) {
- this.key = pair.getKey();
- this.value = pair.getValue();
- this.valueNeedsLookup = AbstractJacksonLayoutCopy.valueNeedsLookup(this.value);
- }
- }
-
- private static class ReadOnlyLogEventWrapper implements LogEvent {
-
- @JsonIgnore
- private final LogEvent event;
-
- public ReadOnlyLogEventWrapper(LogEvent event) {
- this.event = event;
- }
-
- @Override
- public LogEvent toImmutable() {
- return event.toImmutable();
- }
-
- @Override
- public Map getContextMap() {
- return event.getContextMap();
- }
-
- @Override
- public ReadOnlyStringMap getContextData() {
- return event.getContextData();
- }
-
- @Override
- public ThreadContext.ContextStack getContextStack() {
- return event.getContextStack();
- }
-
- @Override
- public String getLoggerFqcn() {
- return event.getLoggerFqcn();
- }
-
- @Override
- public Level getLevel() {
- return event.getLevel();
- }
-
- @Override
- public String getLoggerName() {
- return event.getLoggerName();
- }
-
- @Override
- public Marker getMarker() {
- return event.getMarker();
- }
-
- @Override
- public Message getMessage() {
- return event.getMessage();
- }
-
- @Override
- public long getTimeMillis() {
- return event.getTimeMillis();
- }
-
- @Override
- public Instant getInstant() {
- return event.getInstant();
- }
-
- @Override
- public StackTraceElement getSource() {
- return event.getSource();
- }
-
- @Override
- public String getThreadName() {
- return event.getThreadName();
- }
-
- @Override
- public long getThreadId() {
- return event.getThreadId();
- }
-
- @Override
- public int getThreadPriority() {
- return event.getThreadPriority();
- }
-
- @Override
- public Throwable getThrown() {
- return event.getThrown();
- }
-
- @Override
- public ThrowableProxy getThrownProxy() {
- return event.getThrownProxy();
- }
-
- @Override
- public boolean isEndOfBatch() {
- return event.isEndOfBatch();
- }
-
- @Override
- public boolean isIncludeLocation() {
- return event.isIncludeLocation();
- }
-
- @Override
- public void setEndOfBatch(boolean endOfBatch) {
-
- }
-
- @Override
- public void setIncludeLocation(boolean locationRequired) {
-
- }
-
- @Override
- public long getNanoTime() {
- return event.getNanoTime();
- }
- }
-}
\ No newline at end of file
diff --git a/powertools-logging/src/main/java/software/amazon/lambda/powertools/logging/internal/JacksonFactoryCopy.java b/powertools-logging/src/main/java/software/amazon/lambda/powertools/logging/internal/JacksonFactoryCopy.java
deleted file mode 100644
index 41247cfdb..000000000
--- a/powertools-logging/src/main/java/software/amazon/lambda/powertools/logging/internal/JacksonFactoryCopy.java
+++ /dev/null
@@ -1,117 +0,0 @@
-package software.amazon.lambda.powertools.logging.internal;
-
-import com.fasterxml.jackson.core.PrettyPrinter;
-import com.fasterxml.jackson.core.util.DefaultPrettyPrinter;
-import com.fasterxml.jackson.core.util.MinimalPrettyPrinter;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.ObjectWriter;
-import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter;
-import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider;
-import org.apache.logging.log4j.core.impl.Log4jLogEvent;
-import org.apache.logging.log4j.core.jackson.JsonConstants;
-import org.apache.logging.log4j.core.jackson.Log4jJsonObjectMapper;
-
-import java.util.HashSet;
-import java.util.Set;
-
-@Deprecated
-abstract class JacksonFactoryCopy {
-
- static class JSON extends JacksonFactoryCopy {
-
- private final boolean encodeThreadContextAsList;
- private final boolean includeStacktrace;
- private final boolean stacktraceAsString;
- private final boolean objectMessageAsJsonObject;
-
- public JSON(final boolean encodeThreadContextAsList, final boolean includeStacktrace, final boolean stacktraceAsString, final boolean objectMessageAsJsonObject) {
- this.encodeThreadContextAsList = encodeThreadContextAsList;
- this.includeStacktrace = includeStacktrace;
- this.stacktraceAsString = stacktraceAsString;
- this.objectMessageAsJsonObject = objectMessageAsJsonObject;
- }
-
- @Override
- protected String getPropertNameForContextMap() {
- return JsonConstants.ELT_CONTEXT_MAP;
- }
-
- @Override
- protected String getPropertyNameForTimeMillis() {
- return JsonConstants.ELT_TIME_MILLIS;
- }
-
- @Override
- protected String getPropertyNameForInstant() {
- return JsonConstants.ELT_INSTANT;
- }
-
- @Override
- protected String getPropertNameForSource() {
- return JsonConstants.ELT_SOURCE;
- }
-
- @Override
- protected String getPropertNameForNanoTime() {
- return JsonConstants.ELT_NANO_TIME;
- }
-
- @Override
- protected PrettyPrinter newCompactPrinter() {
- return new MinimalPrettyPrinter();
- }
-
- @Override
- protected ObjectMapper newObjectMapper() {
- return new Log4jJsonObjectMapper(encodeThreadContextAsList, includeStacktrace, stacktraceAsString, objectMessageAsJsonObject);
- }
-
- @Override
- protected PrettyPrinter newPrettyPrinter() {
- return new DefaultPrettyPrinter();
- }
-
- }
-
- abstract protected String getPropertyNameForTimeMillis();
-
- abstract protected String getPropertyNameForInstant();
-
- abstract protected String getPropertNameForContextMap();
-
- abstract protected String getPropertNameForSource();
-
- abstract protected String getPropertNameForNanoTime();
-
- abstract protected PrettyPrinter newCompactPrinter();
-
- abstract protected ObjectMapper newObjectMapper();
-
- abstract protected PrettyPrinter newPrettyPrinter();
-
- ObjectWriter newWriter(final boolean locationInfo, final boolean properties, final boolean compact) {
- return newWriter(locationInfo, properties, compact, false);
- }
-
- ObjectWriter newWriter(final boolean locationInfo, final boolean properties, final boolean compact,
- final boolean includeMillis) {
- final SimpleFilterProvider filters = new SimpleFilterProvider();
- final Set except = new HashSet<>(3);
- if (!locationInfo) {
- except.add(this.getPropertNameForSource());
- }
- if (!properties) {
- except.add(this.getPropertNameForContextMap());
- }
- if (includeMillis) {
- except.add(getPropertyNameForInstant());
- } else {
- except.add(getPropertyNameForTimeMillis());
- }
- except.add(this.getPropertNameForNanoTime());
- filters.addFilter(Log4jLogEvent.class.getName(), SimpleBeanPropertyFilter.serializeAllExcept(except));
- final ObjectWriter writer = this.newObjectMapper().writer(compact ? this.newCompactPrinter() : this.newPrettyPrinter());
- return writer.with(filters);
- }
-
-}
\ No newline at end of file
diff --git a/powertools-logging/src/main/java/software/amazon/lambda/powertools/logging/internal/LambdaJsonLayout.java b/powertools-logging/src/main/java/software/amazon/lambda/powertools/logging/internal/LambdaJsonLayout.java
deleted file mode 100644
index 578937231..000000000
--- a/powertools-logging/src/main/java/software/amazon/lambda/powertools/logging/internal/LambdaJsonLayout.java
+++ /dev/null
@@ -1,243 +0,0 @@
-/*
- * Copyright 2020 Amazon.com, Inc. or its affiliates.
- * Licensed under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package software.amazon.lambda.powertools.logging.internal;
-
-import com.fasterxml.jackson.annotation.JsonAnyGetter;
-import com.fasterxml.jackson.annotation.JsonGetter;
-import com.fasterxml.jackson.annotation.JsonRootName;
-import com.fasterxml.jackson.annotation.JsonUnwrapped;
-import org.apache.logging.log4j.core.Layout;
-import org.apache.logging.log4j.core.LogEvent;
-import org.apache.logging.log4j.core.config.Configuration;
-import org.apache.logging.log4j.core.config.DefaultConfiguration;
-import org.apache.logging.log4j.core.config.Node;
-import org.apache.logging.log4j.core.config.plugins.Plugin;
-import org.apache.logging.log4j.core.config.plugins.PluginBuilderAttribute;
-import org.apache.logging.log4j.core.config.plugins.PluginBuilderFactory;
-import org.apache.logging.log4j.core.jackson.XmlConstants;
-import org.apache.logging.log4j.core.layout.PatternLayout;
-import org.apache.logging.log4j.core.util.KeyValuePair;
-import org.apache.logging.log4j.util.Strings;
-
-import java.io.IOException;
-import java.io.Writer;
-import java.nio.charset.Charset;
-import java.nio.charset.StandardCharsets;
-import java.time.ZoneId;
-import java.time.ZonedDateTime;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.Map;
-
-import static java.time.Instant.ofEpochMilli;
-import static java.time.format.DateTimeFormatter.ISO_ZONED_DATE_TIME;
-
-/***
- * Note: The LambdaJsonLayout should be considered to be deprecated. Please use JsonTemplateLayout instead.
- */
-@Deprecated
-@Plugin(name = "LambdaJsonLayout", category = Node.CATEGORY, elementType = Layout.ELEMENT_TYPE, printObject = true)
-public final class LambdaJsonLayout extends AbstractJacksonLayoutCopy {
- private static final String DEFAULT_FOOTER = "]";
-
- private static final String DEFAULT_HEADER = "[";
-
- static final String CONTENT_TYPE = "application/json";
-
- public static class Builder> extends AbstractJacksonLayoutCopy.Builder
- implements org.apache.logging.log4j.core.util.Builder {
-
- @PluginBuilderAttribute
- private boolean propertiesAsList;
-
- @PluginBuilderAttribute
- private boolean objectMessageAsJsonObject;
-
- public Builder() {
- super();
- setCharset(StandardCharsets.UTF_8);
- }
-
- @Override
- public LambdaJsonLayout build() {
- final boolean encodeThreadContextAsList = isProperties() && propertiesAsList;
- final String headerPattern = toStringOrNull(getHeader());
- final String footerPattern = toStringOrNull(getFooter());
- return new LambdaJsonLayout(getConfiguration(), isLocationInfo(), isProperties(), encodeThreadContextAsList,
- isComplete(), isCompact(), getEventEol(), headerPattern, footerPattern, getCharset(),
- isIncludeStacktrace(), isStacktraceAsString(), isIncludeNullDelimiter(),
- getAdditionalFields(), getObjectMessageAsJsonObject());
- }
-
- public boolean isPropertiesAsList() {
- return propertiesAsList;
- }
-
- public B setPropertiesAsList(final boolean propertiesAsList) {
- this.propertiesAsList = propertiesAsList;
- return asBuilder();
- }
-
- public boolean getObjectMessageAsJsonObject() {
- return objectMessageAsJsonObject;
- }
-
- public B setObjectMessageAsJsonObject(final boolean objectMessageAsJsonObject) {
- this.objectMessageAsJsonObject = objectMessageAsJsonObject;
- return asBuilder();
- }
- }
-
- private LambdaJsonLayout(final Configuration config, final boolean locationInfo, final boolean properties,
- final boolean encodeThreadContextAsList,
- final boolean complete, final boolean compact, final boolean eventEol,
- final String headerPattern, final String footerPattern, final Charset charset,
- final boolean includeStacktrace, final boolean stacktraceAsString,
- final boolean includeNullDelimiter,
- final KeyValuePair[] additionalFields, final boolean objectMessageAsJsonObject) {
- super(config, new JacksonFactoryCopy.JSON(encodeThreadContextAsList, includeStacktrace, stacktraceAsString, objectMessageAsJsonObject).newWriter(
- locationInfo, properties, compact),
- charset, compact, complete, eventEol,
- null,
- PatternLayout.newSerializerBuilder().setConfiguration(config).setPattern(headerPattern).setDefaultPattern(DEFAULT_HEADER).build(),
- PatternLayout.newSerializerBuilder().setConfiguration(config).setPattern(footerPattern).setDefaultPattern(DEFAULT_FOOTER).build(),
- includeNullDelimiter,
- additionalFields);
- }
-
- /**
- * Returns appropriate JSON header.
- *
- * @return a byte array containing the header, opening the JSON array.
- */
- @Override
- public byte[] getHeader() {
- if (!this.complete) {
- return null;
- }
- final StringBuilder buf = new StringBuilder();
- final String str = serializeToString(getHeaderSerializer());
- if (str != null) {
- buf.append(str);
- }
- buf.append(this.eol);
- return getBytes(buf.toString());
- }
-
- /**
- * Returns appropriate JSON footer.
- *
- * @return a byte array containing the footer, closing the JSON array.
- */
- @Override
- public byte[] getFooter() {
- if (!this.complete) {
- return null;
- }
- final StringBuilder buf = new StringBuilder();
- buf.append(this.eol);
- final String str = serializeToString(getFooterSerializer());
- if (str != null) {
- buf.append(str);
- }
- buf.append(this.eol);
- return getBytes(buf.toString());
- }
-
- @Override
- public Map getContentFormat() {
- final Map result = new HashMap<>();
- result.put("version", "2.0");
- return result;
- }
-
- /**
- * @return The content type.
- */
- @Override
- public String getContentType() {
- return CONTENT_TYPE + "; charset=" + this.getCharset();
- }
-
- @PluginBuilderFactory
- public static > B newBuilder() {
- return new Builder().asBuilder();
- }
-
- /**
- * Creates a JSON Layout using the default settings. Useful for testing.
- *
- * @return A JSON Layout.
- */
- public static LambdaJsonLayout createDefaultLayout() {
- return new LambdaJsonLayout(new DefaultConfiguration(), false, false, false, false, false, false,
- DEFAULT_HEADER, DEFAULT_FOOTER, StandardCharsets.UTF_8, true, false, false, null, false);
- }
-
- @Override
- public Object wrapLogEvent(final LogEvent event) {
- Map additionalFieldsMap = resolveAdditionalFields(event);
- // This class combines LogEvent with AdditionalFields during serialization
- return new LogEventWithAdditionalFields(event, additionalFieldsMap);
- }
-
- @Override
- public void toSerializable(final LogEvent event, final Writer writer) throws IOException {
- if (complete && eventCount > 0) {
- writer.append(", ");
- }
- super.toSerializable(event, writer);
- }
-
- private Map resolveAdditionalFields(LogEvent logEvent) {
- // Note: LinkedHashMap retains order
- final Map additionalFieldsMap = new LinkedHashMap<>(additionalFields.length);
-
- // Go over MDC
- logEvent.getContextData().forEach((key, value) -> {
- if (Strings.isNotBlank(key) && value != null) {
- additionalFieldsMap.put(key, value);
- }
- });
-
- return additionalFieldsMap;
- }
-
- @JsonRootName(XmlConstants.ELT_EVENT)
- public static class LogEventWithAdditionalFields {
-
- private final LogEvent logEvent;
- private final Map additionalFields;
-
- public LogEventWithAdditionalFields(LogEvent logEvent, Map additionalFields) {
- this.logEvent = logEvent;
- this.additionalFields = additionalFields;
- }
-
- @JsonUnwrapped
- public Object getLogEvent() {
- return logEvent;
- }
-
- @JsonAnyGetter
- public Map getAdditionalFields() {
- return additionalFields;
- }
-
- @JsonGetter("timestamp")
- public String getTimestamp() {
- return ISO_ZONED_DATE_TIME.format(ZonedDateTime.from(ofEpochMilli(logEvent.getTimeMillis()).atZone(ZoneId.systemDefault())));
- }
- }
-}
diff --git a/powertools-logging/src/main/java/software/amazon/lambda/powertools/logging/internal/LambdaLoggingAspect.java b/powertools-logging/src/main/java/software/amazon/lambda/powertools/logging/internal/LambdaLoggingAspect.java
index 34f3bf312..683d6e705 100644
--- a/powertools-logging/src/main/java/software/amazon/lambda/powertools/logging/internal/LambdaLoggingAspect.java
+++ b/powertools-logging/src/main/java/software/amazon/lambda/powertools/logging/internal/LambdaLoggingAspect.java
@@ -13,67 +13,68 @@
*/
package software.amazon.lambda.powertools.logging.internal;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.OutputStreamWriter;
-import java.util.Map;
-import java.util.Optional;
-import java.util.Random;
-
import com.amazonaws.services.lambda.runtime.Context;
import com.fasterxml.jackson.core.JsonPointer;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
-import org.apache.logging.log4j.Level;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.ThreadContext;
-import org.apache.logging.log4j.core.LoggerContext;
-import org.apache.logging.log4j.core.config.Configurator;
-import org.apache.logging.log4j.core.util.IOUtils;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.DeclarePrecedence;
import org.aspectj.lang.annotation.Pointcut;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.slf4j.MDC;
+import org.slf4j.event.Level;
import software.amazon.lambda.powertools.logging.Logging;
import software.amazon.lambda.powertools.logging.LoggingUtils;
+import java.io.*;
+import java.util.*;
+
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Optional.empty;
import static java.util.Optional.ofNullable;
-import static software.amazon.lambda.powertools.core.internal.LambdaHandlerProcessor.coldStartDone;
-import static software.amazon.lambda.powertools.core.internal.LambdaHandlerProcessor.extractContext;
-import static software.amazon.lambda.powertools.core.internal.LambdaHandlerProcessor.getXrayTraceId;
-import static software.amazon.lambda.powertools.core.internal.LambdaHandlerProcessor.isColdStart;
-import static software.amazon.lambda.powertools.core.internal.LambdaHandlerProcessor.isHandlerMethod;
-import static software.amazon.lambda.powertools.core.internal.LambdaHandlerProcessor.placedOnRequestHandler;
-import static software.amazon.lambda.powertools.core.internal.LambdaHandlerProcessor.placedOnStreamHandler;
-import static software.amazon.lambda.powertools.core.internal.LambdaHandlerProcessor.serviceName;
-import static software.amazon.lambda.powertools.logging.LoggingUtils.appendKey;
-import static software.amazon.lambda.powertools.logging.LoggingUtils.appendKeys;
-import static software.amazon.lambda.powertools.logging.LoggingUtils.objectMapper;
+import static software.amazon.lambda.powertools.core.internal.LambdaHandlerProcessor.*;
+import static software.amazon.lambda.powertools.logging.LoggingUtils.*;
+import static software.amazon.lambda.powertools.logging.internal.PowertoolsLoggedFields.*;
@Aspect
@DeclarePrecedence("*, SqsLargeMessageAspect, LambdaLoggingAspect")
public final class LambdaLoggingAspect {
- private static final Logger LOG = LogManager.getLogger(LambdaLoggingAspect.class);
+ private static final Logger LOG = LoggerFactory.getLogger(LambdaLoggingAspect.class);
private static final Random SAMPLER = new Random();
private static final String LOG_LEVEL = System.getenv("POWERTOOLS_LOG_LEVEL");
private static final String SAMPLING_RATE = System.getenv("POWERTOOLS_LOGGER_SAMPLE_RATE");
- private static Level LEVEL_AT_INITIALISATION;
+ private static Level LEVEL_AT_INITIALISATION; /* not final for test purpose */
+
+ private static final LoggingManager loggingManager;
static {
+ loggingManager = loadLoggingManager();
+
+ LEVEL_AT_INITIALISATION = loggingManager.getLogLevel(LOG);
+
if (null != LOG_LEVEL) {
- resetLogLevels(Level.getLevel(LOG_LEVEL));
+ resetLogLevels(Level.valueOf(LOG_LEVEL));
}
+ }
- LEVEL_AT_INITIALISATION = LOG.getLevel();
+ private static LoggingManager loadLoggingManager() {
+ ServiceLoader loggingManagers = ServiceLoader.load(LoggingManager.class);
+ List loggingManagerList = new ArrayList<>();
+ for (LoggingManager loggingManager : loggingManagers) {
+ loggingManagerList.add(loggingManager);
+ }
+ if (loggingManagerList.isEmpty()) {
+ throw new IllegalStateException("No LoggingManager was found on the classpath");
+ } else if (loggingManagerList.size() > 1) {
+ throw new IllegalStateException("Multiple LoggingManagers were found on the classpath: " + loggingManagerList);
+ } else {
+ return loggingManagerList.get(0);
+ }
}
@SuppressWarnings({"EmptyMethod"})
@@ -90,13 +91,13 @@ public Object around(ProceedingJoinPoint pjp,
Context extractedContext = extractContext(pjp);
- if(null != extractedContext) {
- appendKeys(DefaultLambdaFields.values(extractedContext));
- appendKey("coldStart", isColdStart() ? "true" : "false");
- appendKey("service", serviceName());
+ if (null != extractedContext) {
+ appendKeys(PowertoolsLoggedFields.setValuesFromLambdaContext(extractedContext));
+ appendKey(FUNCTION_COLD_START.getName(), isColdStart() ? "true" : "false");
+ appendKey(SERVICE.getName(), serviceName());
}
- getXrayTraceId().ifPresent(xRayTraceId -> appendKey("xray_trace_id", xRayTraceId));
+ getXrayTraceId().ifPresent(xRayTraceId -> appendKey(FUNCTION_TRACE_ID.getName(), xRayTraceId));
if (logging.logEvent()) {
proceedArgs = logEvent(pjp);
@@ -108,8 +109,8 @@ public Object around(ProceedingJoinPoint pjp,
Object proceed = pjp.proceed(proceedArgs);
- if(logging.clearState()) {
- ThreadContext.clearMap();
+ if (logging.clearState()) {
+ MDC.clear();
}
coldStartDone();
@@ -117,9 +118,7 @@ public Object around(ProceedingJoinPoint pjp,
}
private static void resetLogLevels(Level logLevel) {
- LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
- Configurator.setAllLevels(LogManager.getRootLogger().getName(), logLevel);
- ctx.updateLoggers();
+ loggingManager.resetLogLevel(logLevel);
}
private void setLogLevelBasedOnSamplingRate(final ProceedingJoinPoint pjp,
@@ -133,7 +132,7 @@ private void setLogLevelBasedOnSamplingRate(final ProceedingJoinPoint pjp,
return;
}
- appendKey("samplingRate", String.valueOf(samplingRate));
+ appendKey(PowertoolsLoggedFields.SAMPLING_RATE.getName(), String.valueOf(samplingRate));
if (samplingRate == 0) {
return;
@@ -146,7 +145,7 @@ private void setLogLevelBasedOnSamplingRate(final ProceedingJoinPoint pjp,
LOG.debug("Changed log level to DEBUG based on Sampling configuration. " +
"Sampling Rate: {}, Sampler Value: {}.", samplingRate, sample);
- } else if (LEVEL_AT_INITIALISATION != LOG.getLevel()) {
+ } else if (LEVEL_AT_INITIALISATION != loggingManager.getLogLevel(LOG)) {
resetLogLevels(LEVEL_AT_INITIALISATION);
}
}
@@ -248,8 +247,11 @@ private byte[] bytesFromInputStreamSafely(final InputStream inputStream) throws
try (ByteArrayOutputStream out = new ByteArrayOutputStream();
InputStreamReader reader = new InputStreamReader(inputStream, UTF_8)) {
OutputStreamWriter writer = new OutputStreamWriter(out, UTF_8);
-
- IOUtils.copy(reader, writer);
+ int n;
+ char[] buffer = new char[4096];
+ while (-1 != (n = reader.read(buffer))) {
+ writer.write(buffer, 0, n);
+ }
writer.flush();
return out.toByteArray();
}
@@ -266,6 +268,6 @@ private Optional asJson(final ProceedingJoinPoint pjp,
}
private Logger logger(final ProceedingJoinPoint pjp) {
- return LogManager.getLogger(pjp.getSignature().getDeclaringType());
+ return LoggerFactory.getLogger(pjp.getSignature().getDeclaringType());
}
}
diff --git a/powertools-logging/src/main/java/software/amazon/lambda/powertools/logging/internal/LoggingManager.java b/powertools-logging/src/main/java/software/amazon/lambda/powertools/logging/internal/LoggingManager.java
new file mode 100644
index 000000000..4850c9413
--- /dev/null
+++ b/powertools-logging/src/main/java/software/amazon/lambda/powertools/logging/internal/LoggingManager.java
@@ -0,0 +1,30 @@
+package software.amazon.lambda.powertools.logging.internal;
+
+import org.slf4j.Logger;
+import org.slf4j.event.Level;
+
+/**
+ * Due to limitations of SLF4J, we need to rely on implementations for some operations:
+ *
+ *
Accessing to all loggers and change their Level
+ *
Retrieving the log Level of a Logger
+ *
+ *
+ * Implementations are provided in submodules and loaded thanks to a {@link java.util.ServiceLoader}
+ * (define a file named software.amazon.lambda.powertools.logging.internal.LoggingManager in src/main/resources/META-INF/services with the qualified name of the implementation).
+ *
+ */
+public interface LoggingManager {
+ /**
+ * Change the log Level of all loggers (named and root)
+ * @param logLevel the log Level (slf4j) to apply
+ */
+ void resetLogLevel(Level logLevel);
+
+ /**
+ * Retrieve the log Level of a specific logger
+ * @param logger the logger (slf4j) for which to retrieve the log Level
+ * @return the Level (slf4j) of this logger. Note that SLF4J only support ERROR, WARN, INFO, DEBUG, TRACE while some frameworks may support others (OFF, FATAL, ...)
+ */
+ Level getLogLevel(Logger logger);
+}
diff --git a/powertools-logging/src/main/java/software/amazon/lambda/powertools/logging/internal/DefaultLambdaFields.java b/powertools-logging/src/main/java/software/amazon/lambda/powertools/logging/internal/PowertoolsLoggedFields.java
similarity index 64%
rename from powertools-logging/src/main/java/software/amazon/lambda/powertools/logging/internal/DefaultLambdaFields.java
rename to powertools-logging/src/main/java/software/amazon/lambda/powertools/logging/internal/PowertoolsLoggedFields.java
index a50b292b2..b8d212340 100644
--- a/powertools-logging/src/main/java/software/amazon/lambda/powertools/logging/internal/DefaultLambdaFields.java
+++ b/powertools-logging/src/main/java/software/amazon/lambda/powertools/logging/internal/PowertoolsLoggedFields.java
@@ -16,26 +16,37 @@
import com.amazonaws.services.lambda.runtime.Context;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
-
-enum DefaultLambdaFields {
- FUNCTION_NAME("functionName"),
- FUNCTION_VERSION("functionVersion"),
- FUNCTION_ARN("functionArn"),
- FUNCTION_MEMORY_SIZE("functionMemorySize"),
- FUNCTION_REQUEST_ID("function_request_id");
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+public enum PowertoolsLoggedFields {
+ FUNCTION_NAME("function_name"),
+ FUNCTION_VERSION("function_version"),
+ FUNCTION_ARN("function_arn"),
+ FUNCTION_MEMORY_SIZE("function_memory_size"),
+ FUNCTION_REQUEST_ID("function_request_id"),
+ FUNCTION_COLD_START("cold_start"),
+ FUNCTION_TRACE_ID("xray_trace_id"),
+ SAMPLING_RATE("sampling_rate"),
+ SERVICE("service");
private final String name;
- DefaultLambdaFields(String name) {
+ PowertoolsLoggedFields(String name) {
this.name = name;
}
+ public static List stringValues() {
+ return Stream.of(values()).map(PowertoolsLoggedFields::getName).collect(Collectors.toList());
+ }
+
public String getName() {
return name;
}
- static Map values(Context context) {
+ static Map setValuesFromLambdaContext(Context context) {
Map hashMap = new HashMap<>();
hashMap.put(FUNCTION_NAME.name, context.getFunctionName());
diff --git a/powertools-logging/src/main/java/software/amazon/lambda/powertools/logging/internal/PowertoolsResolver.java b/powertools-logging/src/main/java/software/amazon/lambda/powertools/logging/internal/PowertoolsResolver.java
deleted file mode 100644
index c392e2ed9..000000000
--- a/powertools-logging/src/main/java/software/amazon/lambda/powertools/logging/internal/PowertoolsResolver.java
+++ /dev/null
@@ -1,51 +0,0 @@
-package software.amazon.lambda.powertools.logging.internal;
-
-import org.apache.logging.log4j.core.LogEvent;
-import org.apache.logging.log4j.layout.template.json.resolver.EventResolver;
-import org.apache.logging.log4j.layout.template.json.util.JsonWriter;
-import org.apache.logging.log4j.util.ReadOnlyStringMap;
-
-final class PowertoolsResolver implements EventResolver {
-
- private final EventResolver internalResolver;
-
- PowertoolsResolver() {
- internalResolver = new EventResolver() {
- @Override
- public boolean isResolvable(LogEvent value) {
- ReadOnlyStringMap contextData = value.getContextData();
- return null != contextData && !contextData.isEmpty();
- }
-
- @Override
- public void resolve(LogEvent logEvent, JsonWriter jsonWriter) {
- StringBuilder stringBuilder = jsonWriter.getStringBuilder();
- // remove dummy field to kick inn powertools resolver
- stringBuilder.setLength(stringBuilder.length() - 4);
-
- // Inject all the context information.
- ReadOnlyStringMap contextData = logEvent.getContextData();
- contextData.forEach((key, value) -> {
- jsonWriter.writeSeparator();
- jsonWriter.writeString(key);
- stringBuilder.append(':');
- jsonWriter.writeValue(value);
- });
- }
- };
- }
-
- static String getName() {
- return "powertools";
- }
-
- @Override
- public void resolve(LogEvent value, JsonWriter jsonWriter) {
- internalResolver.resolve(value, jsonWriter);
- }
-
- @Override
- public boolean isResolvable(LogEvent value) {
- return internalResolver.isResolvable(value);
- }
-}
diff --git a/powertools-logging/src/main/resources/LambdaEcsLayout.json b/powertools-logging/src/main/resources/LambdaEcsLayout.json
deleted file mode 100644
index 4ab9c7ce2..000000000
--- a/powertools-logging/src/main/resources/LambdaEcsLayout.json
+++ /dev/null
@@ -1,52 +0,0 @@
-{
- "@timestamp": {
- "$resolver": "timestamp",
- "pattern": {
- "format": "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'",
- "timeZone": "UTC"
- }
- },
- "ecs.version": "1.2.0",
- "log.level": {
- "$resolver": "level",
- "field": "name"
- },
- "message": {
- "$resolver": "message",
- "stringified": true
- },
- "process.thread.name": {
- "$resolver": "thread",
- "field": "name"
- },
- "log.logger": {
- "$resolver": "logger",
- "field": "name"
- },
- "labels": {
- "$resolver": "mdc",
- "flatten": true,
- "stringified": true
- },
- "tags": {
- "$resolver": "ndc"
- },
- "error.type": {
- "$resolver": "exception",
- "field": "className"
- },
- "error.message": {
- "$resolver": "exception",
- "field": "message"
- },
- "error.stack_trace": {
- "$resolver": "exception",
- "field": "stackTrace",
- "stackTrace": {
- "stringified": true
- }
- },
- "": {
- "$resolver": "powertools"
- }
-}
\ No newline at end of file
diff --git a/powertools-logging/src/main/resources/LambdaJsonLayout.json b/powertools-logging/src/main/resources/LambdaJsonLayout.json
deleted file mode 100644
index dfc1fc78f..000000000
--- a/powertools-logging/src/main/resources/LambdaJsonLayout.json
+++ /dev/null
@@ -1,89 +0,0 @@
-{
- "timestamp": {
- "$resolver": "timestamp"
- },
- "instant": {
- "epochSecond": {
- "$resolver": "timestamp",
- "epoch": {
- "unit": "secs",
- "rounded": true
- }
- },
- "nanoOfSecond": {
- "$resolver": "timestamp",
- "epoch": {
- "unit": "secs.nanos"
- }
- }
- },
- "thread": {
- "$resolver": "thread",
- "field": "name"
- },
- "level": {
- "$resolver": "level",
- "field": "name"
- },
- "loggerName": {
- "$resolver": "logger",
- "field": "name"
- },
- "message": {
- "$resolver": "message",
- "stringified": true
- },
- "thrown": {
- "message": {
- "$resolver": "exception",
- "field": "message"
- },
- "name": {
- "$resolver": "exception",
- "field": "className"
- },
- "extendedStackTrace": {
- "$resolver": "exception",
- "field": "stackTrace"
- }
- },
- "contextStack": {
- "$resolver": "ndc"
- },
- "endOfBatch": {
- "$resolver": "endOfBatch"
- },
- "loggerFqcn": {
- "$resolver": "logger",
- "field": "fqcn"
- },
- "threadId": {
- "$resolver": "thread",
- "field": "id"
- },
- "threadPriority": {
- "$resolver": "thread",
- "field": "priority"
- },
- "source": {
- "class": {
- "$resolver": "source",
- "field": "className"
- },
- "method": {
- "$resolver": "source",
- "field": "methodName"
- },
- "file": {
- "$resolver": "source",
- "field": "fileName"
- },
- "line": {
- "$resolver": "source",
- "field": "lineNumber"
- }
- },
- "": {
- "$resolver": "powertools"
- }
-}
diff --git a/powertools-logging/src/main/resources/log4j2.component.properties b/powertools-logging/src/main/resources/log4j2.component.properties
deleted file mode 100644
index 3c392dd13..000000000
--- a/powertools-logging/src/main/resources/log4j2.component.properties
+++ /dev/null
@@ -1,2 +0,0 @@
-log4j.layout.jsonTemplate.timestampFormatPattern=yyyy-MM-dd'T'HH:mm:ss.SSSZz
-#log4j.layout.jsonTemplate.timeZone=
\ No newline at end of file
diff --git a/powertools-logging/src/test/java/org/apache/logging/log4j/core/layout/LambdaJsonLayoutTest.java b/powertools-logging/src/test/java/org/apache/logging/log4j/core/layout/LambdaJsonLayoutTest.java
deleted file mode 100644
index 5fc0398d1..000000000
--- a/powertools-logging/src/test/java/org/apache/logging/log4j/core/layout/LambdaJsonLayoutTest.java
+++ /dev/null
@@ -1,140 +0,0 @@
-/*
- * Copyright 2020 Amazon.com, Inc. or its affiliates.
- * Licensed under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.logging.log4j.core.layout;
-
-import java.io.IOException;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.nio.channels.FileChannel;
-import java.nio.file.Files;
-import java.nio.file.Paths;
-import java.nio.file.StandardOpenOption;
-import java.util.Map;
-
-import com.amazonaws.services.lambda.runtime.Context;
-import com.amazonaws.services.lambda.runtime.RequestHandler;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.apache.logging.log4j.Level;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-import org.mockito.Mock;
-import software.amazon.lambda.powertools.logging.handlers.PowerLogToolEnabled;
-import software.amazon.lambda.powertools.logging.handlers.PowerLogToolSamplingEnabled;
-import software.amazon.lambda.powertools.logging.internal.LambdaLoggingAspect;
-
-import static java.util.Collections.emptyMap;
-import static org.apache.commons.lang3.reflect.FieldUtils.writeStaticField;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.fail;
-import static org.mockito.Mockito.when;
-import static org.mockito.MockitoAnnotations.openMocks;
-
-class LambdaJsonLayoutTest {
-
- private RequestHandler