-
Notifications
You must be signed in to change notification settings - Fork 274
Added LogbookCustomizer for Spring #2234
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?
Changes from all commits
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 |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ | |
| import lombok.Generated; | ||
| import org.apache.http.client.HttpClient; | ||
| import org.apiguardian.api.API; | ||
| import org.springframework.beans.factory.ObjectProvider; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.beans.factory.annotation.Value; | ||
| import org.springframework.boot.autoconfigure.AutoConfigureAfter; | ||
|
|
@@ -22,21 +23,11 @@ | |
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
| import org.springframework.context.annotation.Primary; | ||
| import org.springframework.context.annotation.Scope; | ||
| import org.springframework.core.Ordered; | ||
| import org.springframework.core.annotation.Order; | ||
| import org.springframework.security.web.SecurityFilterChain; | ||
| import org.zalando.logbook.BodyFilter; | ||
| import org.zalando.logbook.CorrelationId; | ||
| import org.zalando.logbook.HeaderFilter; | ||
| import org.zalando.logbook.HttpLogFormatter; | ||
| import org.zalando.logbook.HttpLogWriter; | ||
| import org.zalando.logbook.HttpRequest; | ||
| import org.zalando.logbook.Logbook; | ||
| import org.zalando.logbook.PathFilter; | ||
| import org.zalando.logbook.QueryFilter; | ||
| import org.zalando.logbook.RequestFilter; | ||
| import org.zalando.logbook.ResponseFilter; | ||
| import org.zalando.logbook.Sink; | ||
| import org.zalando.logbook.Strategy; | ||
| import org.zalando.logbook.*; | ||
|
Member
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 tend to not use start imports, could you please change it? |
||
| import org.zalando.logbook.attributes.AttributeExtractor; | ||
| import org.zalando.logbook.core.attributes.CompositeAttributeExtractor; | ||
| import org.zalando.logbook.attributes.NoOpAttributeExtractor; | ||
|
|
@@ -76,7 +67,6 @@ | |
| import java.util.Set; | ||
| import java.util.TreeSet; | ||
| import java.util.function.Predicate; | ||
| import java.util.stream.Collectors; | ||
| import java.util.stream.Stream; | ||
|
|
||
| import static jakarta.servlet.DispatcherType.ASYNC; | ||
|
|
@@ -111,7 +101,24 @@ public LogbookAutoConfiguration(final LogbookProperties properties) { | |
| @API(status = INTERNAL) | ||
| @Bean | ||
| @ConditionalOnMissingBean(Logbook.class) | ||
| public Logbook logbook( | ||
| public Logbook logbook(LogbookCreator.Builder builder) { | ||
| return builder.build(); | ||
| } | ||
|
|
||
| @API(status = INTERNAL) | ||
| @Bean | ||
| @ConditionalOnMissingBean(LogbookCreator.Builder.class) | ||
| @Scope("prototype") | ||
| public LogbookCreator.Builder logbookBuilder(final ObjectProvider<LogbookCustomizer> customizers) { | ||
|
Member
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. I wonder if we even need this prototype bean. Wouldn't it work the same if logbook bean would accept customizers and apply them? e.g. |
||
| var builder = Logbook.builder(); | ||
| customizers.orderedStream().forEach(customizer -> customizer.customize(builder)); | ||
| return builder; | ||
| } | ||
|
|
||
| @Bean | ||
| @Order(0) | ||
| @ConditionalOnMissingBean(name = "defaultLogbookConfiguration") | ||
| public LogbookCustomizer defaultLogbookConfiguration( | ||
| final Predicate<HttpRequest> condition, | ||
| final CorrelationId correlationId, | ||
| final List<HeaderFilter> headerFilters, | ||
|
|
@@ -123,8 +130,7 @@ public Logbook logbook( | |
| final Strategy strategy, | ||
| final AttributeExtractor attributeExtractor, | ||
| final Sink sink) { | ||
|
|
||
| return Logbook.builder() | ||
| return builder -> builder | ||
| .condition(mergeWithExcludes(mergeWithIncludes(condition))) | ||
| .correlationId(correlationId) | ||
| .headerFilters(headerFilters) | ||
|
|
@@ -135,8 +141,7 @@ public Logbook logbook( | |
| .responseFilters(responseFilters) | ||
| .strategy(strategy) | ||
| .attributeExtractor(attributeExtractor) | ||
| .sink(sink) | ||
| .build(); | ||
| .sink(sink); | ||
| } | ||
|
|
||
| private Collection<BodyFilter> mergeWithTruncation(List<BodyFilter> bodyFilters) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package org.zalando.logbook.autoconfigure; | ||
|
|
||
| import org.zalando.logbook.LogbookCreator; | ||
|
|
||
| @FunctionalInterface | ||
| public interface LogbookCustomizer { | ||
| void customize(LogbookCreator.Builder builder); | ||
| } |
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.
sorry, intellij automatically made these changes. Are they ok, or shall I revert them?