Skip to content

Commit 2b657a5

Browse files
committed
feat: Powertools will now override the Log4J log level configured if the 'LOG_LEVEL' environment variable is set to a Log4J Level (INFO, ERROR etc...)
1 parent e1dcfa6 commit 2b657a5

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/main/java/software/amazon/lambda/logging/internal/LambdaLoggingAspect.java

+12
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@
1111

1212
import com.amazonaws.services.lambda.runtime.Context;
1313
import com.fasterxml.jackson.databind.ObjectMapper;
14+
import org.apache.logging.log4j.Level;
1415
import org.apache.logging.log4j.LogManager;
1516
import org.apache.logging.log4j.Logger;
1617
import org.apache.logging.log4j.ThreadContext;
18+
import org.apache.logging.log4j.core.LoggerContext;
19+
import org.apache.logging.log4j.core.config.Configurator;
1720
import org.apache.logging.log4j.core.util.IOUtils;
1821
import org.aspectj.lang.ProceedingJoinPoint;
1922
import org.aspectj.lang.annotation.Around;
@@ -33,6 +36,15 @@
3336
@Aspect
3437
public final class LambdaLoggingAspect {
3538
private static final ObjectMapper mapper = new ObjectMapper();
39+
private static final String LOG_LEVEL = System.getenv("LOG_LEVEL");
40+
41+
static {
42+
if (LOG_LEVEL != null) {
43+
LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
44+
Configurator.setAllLevels(LogManager.getRootLogger().getName(), Level.getLevel(LOG_LEVEL));
45+
ctx.updateLoggers();
46+
}
47+
}
3648

3749
@SuppressWarnings({"EmptyMethod", "unused"})
3850
@Pointcut("@annotation(powerToolsLogging)")

0 commit comments

Comments
 (0)