-
Notifications
You must be signed in to change notification settings - Fork 90
feat: Add support for POWERTOOLS_LOGGER_LOG_EVENT #1510
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 9 commits
d5e3ee5
d9b44ba
3f6a477
288b676
da1c37c
03094f1
6a53b4c
5df3b3b
d990ef8
3e3b402
4645b62
93c3e69
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,7 @@ | |
import com.fasterxml.jackson.core.JsonPointer; | ||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
|
@@ -42,6 +43,7 @@ | |
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.Random; | ||
|
||
import org.apache.logging.log4j.Level; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
@@ -65,6 +67,7 @@ public final class LambdaLoggingAspect { | |
|
||
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 Boolean LOG_EVENT; | ||
|
||
private static Level LEVEL_AT_INITIALISATION; | ||
|
||
|
@@ -74,6 +77,13 @@ public final class LambdaLoggingAspect { | |
} | ||
|
||
LEVEL_AT_INITIALISATION = LOG.getLevel(); | ||
|
||
String logEvent = System.getenv("POWERTOOLS_LOGGER_LOG_EVENT"); | ||
if (logEvent != null) { | ||
LOG_EVENT = Boolean.parseBoolean(logEvent); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we try catch if the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could with some effort, but I think this is before logger is initialized, though |
||
} else { | ||
LOG_EVENT = false; | ||
} | ||
} | ||
|
||
private static void resetLogLevels(Level logLevel) { | ||
|
@@ -104,7 +114,9 @@ public Object around(ProceedingJoinPoint pjp, | |
|
||
getXrayTraceId().ifPresent(xRayTraceId -> appendKey("xray_trace_id", xRayTraceId)); | ||
|
||
if (logging.logEvent()) { | ||
// Check that the environment variable was enabled explicitly | ||
// Or that the handler was annotated with @Logging(logEvent = true) | ||
if (LOG_EVENT || logging.logEvent()) { | ||
proceedArgs = logEvent(pjp); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright 2023 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.handlers; | ||
|
||
import com.amazonaws.services.lambda.runtime.Context; | ||
import com.amazonaws.services.lambda.runtime.RequestHandler; | ||
import software.amazon.lambda.powertools.logging.Logging; | ||
|
||
public class PowerToolLogEventDisabled implements RequestHandler<Object, Object> { | ||
|
||
@Logging(logEvent = false) | ||
@Override | ||
public Object handleRequest(Object input, Context context) { | ||
return null; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we simplify this whole paragraph with the same content as python: https://docs.powertools.aws.dev/lambda/python/latest/core/logger/#logging-incoming-event