Skip to content

Refactor: guard all logger calls with isXxxEnabled() checks#101

Merged
mercyblitz merged 14 commits intomainfrom
copilot/refactor-logging-to-check-trace-enabled
Mar 27, 2026
Merged

Refactor: guard all logger calls with isXxxEnabled() checks#101
mercyblitz merged 14 commits intomainfrom
copilot/refactor-logging-to-check-trace-enabled

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 25, 2026

Unguarded logger calls evaluate their arguments eagerly regardless of log level, causing unnecessary string construction, method calls, and lambda execution at runtime.

Changes

  • Wrapped all logger.trace(...), logger.info(...), and logger.warn(...) calls across 7 files in the appropriate isXxxEnabled() guard
  • Grouped consecutive trace calls (e.g. forEach lambda in ServiceInstanceUtils) under a single guard block to avoid redundant level checks

Before:

logger.trace("The ServerProperties property is changed to: {}", getProperties(environment, serverPropertyNames));

After:

if (logger.isTraceEnabled()) {
    logger.trace("The ServerProperties property is changed to: {}", getProperties(environment, serverPropertyNames));
}

Files affected

File Level Calls
DecoratedFeignComponent trace 2
FeignClientSpecificationPostProcessor trace 1
TomcatDynamicConfigurationListener trace 3
ServiceInstanceUtils trace 3 (incl. forEach lambda)
ServiceRegistrationEndpoint info, warn 2
ServiceDeregistrationEndpoint info, warn 2
WebServiceRegistryAutoConfiguration trace 1

Bump parent POM and dependency versions; update CI workflow
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 26, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ Complexity Δ
...configure/WebServiceRegistryAutoConfiguration.java 100.00% <100.00%> (ø) 12.00 <0.00> (+1.00)
...gistry/endpoint/ServiceDeregistrationEndpoint.java 100.00% <100.00%> (ø) 5.00 <0.00> (+2.00)
...registry/endpoint/ServiceRegistrationEndpoint.java 100.00% <100.00%> (ø) 7.00 <0.00> (+2.00)
...loud/client/service/util/ServiceInstanceUtils.java 100.00% <100.00%> (ø) 23.00 <1.00> (+2.00)
...mcat/event/TomcatDynamicConfigurationListener.java 100.00% <100.00%> (ø) 26.00 <0.00> (+3.00)
...igure/FeignClientAutoRefreshAutoConfiguration.java 100.00% <100.00%> (ø) 7.00 <1.00> (ø)
...nfigure/FeignClientSpecificationPostProcessor.java 100.00% <100.00%> (ø) 7.00 <0.00> (+1.00)
.../openfeign/components/DecoratedFeignComponent.java 100.00% <100.00%> (ø) 20.00 <2.00> (+2.00)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Annotate multiple test classes with @SpringLoggingTest to enable consistent test logging and add a new FeignClientSpecificationPostProcessorTest. Adjust Feign auto-refresh code: simplify ConditionalOnBean to use Marker, statically import NoOpRequestInterceptor.INSTANCE, and make AUTO_REFRESH_CAPABILITY_CLASS, FEIGN_CLIENT_SPECIFICATION_CLASS and injectAutoRefreshCapability package-private to allow testing. Update parent POM to add junit-jupiter.version and import the JUnit BOM for consistent test dependency management.
Change testStart() to testStart(int index) and wrap its assertions in an if (index == 0) block so the assertions only run for index 0. This adapts the test for parameterized or repeated invocations while preserving the original assertion behavior.
Change excludeMappings from private(Set) to package-private(Collection) so it can be accessed within the package and accept any Collection<WebEndpointMapping>. Iteration logic remains unchanged.
Remove the final newline character from microsphere-spring-cloud-commons/src/test/java/io/microsphere/spring/cloud/client/service/registry/autoconfigure/WebMvcServiceRegistryAutoConfigurationTest.java. This is a non-functional whitespace/formatting change.
Replace @SpringLoggingTest with @LoggingLevelsTest and update imports. Add a new test (testExcludeMappings) that constructs a WebEndpointMapping, injects WebServiceRegistryAutoConfiguration, and verifies excludeMappings removes the mapping. Also add static imports for newLinkedList, ofList and GET, and adjust references to use this.registration for clarity.
Delete the unused import and the @SpringLoggingTest annotation from BaseServiceRegistrationEndpointTest, cleaning up the test class by removing the SpringLoggingTest extension usage.
Replace the previous conditional/parameterized testStart with a simpler test annotated with @LoggingLevelsTest(levels = "ERROR"). The test now asserts that start() returns the same value as isRunning(), called twice, removing redundant true/false assertions and unused static imports. Added the LoggingLevelsTest import and cleaned up imports accordingly.
Replace class-level @SpringLoggingTest with the more granular @LoggingLevelsTest. Updated import to io.microsphere.logging.test.jupiter.LoggingLevelsTest, removed the @SpringLoggingTest annotation on the class, and added @LoggingLevelsTest(levels = "ERROR") to the testAttachMetadata method to scope logging level for that test.
Replace assertFalse/assertTrue with assertEquals assertions that compare endpoint.isRunning() to stop()/start() results for clearer intent. Add import and annotate testStop with @LoggingLevelsTest(levels = "ERROR"). Remove unused static imports of assertFalse/assertTrue.
Clean up import ordering and duplicates in test classes. Move the static getLogger import to a consistent location, add or relocate the Logger import as needed, and tidy blank lines in BaseTest.java and ObservableFeignInvocationHandler.java. No functional changes.
Move the static import of LoggerFactory.getLogger to be grouped with other imports and add a blank line for improved import formatting in the test AQueryMapEncoder. No functional changes; only import ordering/formatting.
Adjust import ordering in BQueryMapEncoder test: move the static import of LoggerFactory.getLogger below other imports and add spacing. No functional changes; only formatting/organizing imports.
@sonarqubecloud
Copy link
Copy Markdown

@mercyblitz mercyblitz merged commit 48ad907 into main Mar 27, 2026
14 checks passed
@mercyblitz mercyblitz deleted the copilot/refactor-logging-to-check-trace-enabled branch March 27, 2026 03:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants