-
Notifications
You must be signed in to change notification settings - Fork 98
feat(logging): Support functional interface in addition to AspectJ @Logging
annotation
#2205
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
base: main
Are you sure you want to change the base?
Conversation
…on is not guaranteed.
…e class is in internal package.
Just one small observation on the API design and developer experience. Could we add to the API the possibility to create a functional wrapper that handles the try-finally automatically? I think this is what you mention in the #2202 issue For example: PowertoolsLogging.withLogging(context, config, () -> {
log.info("Processing request");
return "Hello World";
}); |
Yes, I like this idea. I'll implement such a wrapper function. Correct, issue #2202 will abstract such wrappers away from individual utilities to a middleware approach which is more scalable. But I like the idea of having a functional wrapper for an individual utility as well for customers who simply want to get started with a utility. |
@Logging
annotation
|
Summary
This PR introduces an alternative functional interface to the Logging utility that does not depend on the AspectJ
@Logging
annotation. We re-usePowertoolsLogging
as entry point for the Powertools logging experience which exposes two new methods:initializeLogging()
– has some method overloads for convenienceclearState()
– can optionally clear the logging context as wellThis is also thread-safe now.
We also add a new E2E test asserting that it yields the exact same outputs as the AspectJ aspect based way.
The before and after compared to AspectJ looks like this:
Usage with AspectJ
Usage without AspectJ
Note: In this small RFC I am investigating an improvement to this imperative API leveraging a more modern functional Middleware approach similar to TypeScript middy.js. See #2202
Changes
Issue number: #2204
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.