Is there a way to change event logging to debug instead of info #4265
Replies: 1 comment 1 reply
-
Hi @FlemmingBehrend, thank you for opening this discussion. Generally speaking we wouldn't advise to follow that pattern and leave the With that said, if your use case allows it, then I can see why you'd want to emit that log as class MyLogger extends Logger {
public logEventIfEnabled(event: unknown, overwriteValue?: boolean): void {
if (!this.shouldLogEvent(overwriteValue)) return;
this.debug('event', { event });
}
}
const log = MyLogger({
// ... your existing config
}) This way you'd be taking over the internal method/logic used to determine if the event payload should be logged, which gives you the ability to control the log level. The pattern of extending the Logger class is relatively common and I've seen many customers use it when they want to have more control over certain aspects that are not exposed via configuration. This would be a medium term solution, however if you think this is a common enough of a need, maybe we could have a discussion on whether this should be the default behavior (most definitely in a future major version) or be configurable in an easy way (perhaps via environment variable/constructor prop).
As a final side note, make sure to test how sampling and buffering play together. If I remember correctly, once buffering is enabled, even those debug logs that were part of a sampled invocations will be buffered - so essentially you'd be never seeing these logs unless there's an error. If this is what you intended, then no action required, but this sentence from your original post suggests you might be expecting something different to happen. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
What do I want to achieve?
I want to use powertools logging to log successful lambda invocations with a sampling rate of 0.1, and when an error happens I want to always log all debug statements.
I have the following setup for all lambda functions in production
The problem
My problem is that the input event to the lambda function is logged as INFO and therefore is always applied to the CloudWatch logs.
I would like to only log input events for the lambda function if an error occurs.
I can choose not to use injectLambdaContexts logEvent feature and manually add debug logs to all my lambda functions to log the event, but it seams to go against what is the idea with logEvent.
Is there a way to change the logEvent to log as DEBUG instead of INFO?
Beta Was this translation helpful? Give feedback.
All reactions