Repository navigation
Consolidate SLF4J level dispatch into a new LogUtil - #3527
Conversation
PerfDataUtil.handleError and ExceptionUtil.logAtLevel each carried their own five-way LogLevel switch. Hoist the dispatch into oshi.util.LogUtil and have both delegate. ExceptionUtil.logAtLevel keeps its signature, so oshi-core-ffm and any downstream caller are unaffected. LogUtil.isEnabled restores the capability of Logger#isEnabledForLevel that #3432 had to drop for slf4j 1.x compatibility. That lets handleError keep skipping FormatUtil.formatError when the level is off, without reintroducing an inline switch to do it. handleError also double-formatted an already-formatted string: FormatUtil.formatError returns the output of String.format, and the result was passed through String.format again with no arguments. PerfCounterQueryHandler had the same copy-paste, fixed there as well; its isWarnEnabled guards are left alone, since both log at a level known at the call site and can check it directly. Widen the forbidden-apis ban from org.slf4j.event.Level to the whole org.slf4j.event package. slf4j-api 1.7.5 has no such package at all, so every type in it breaks the same hosts that motivated #3524 and #3525. The level switch now lives in oshi-common, where a cross-platform test covers all ten branches. Previously the only fully covered copy was in PerfDataUtil, reachable only on Windows CI.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (9)
💤 Files with no reviewable changes (1)
📜 Recent review details⏰ Context from checks skipped due to timeout. (6)
🧰 Additional context used🧠 Learnings (2)📚 Learning: 2026-04-12T19:22:09.716ZApplied to files:
📚 Learning: 2026-07-06T19:25:59.225ZApplied to files:
🔇 Additional comments (8)
📝 WalkthroughWalkthroughThe PR adds ChangesLogging consolidation
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant ExceptionUtil
participant PerfDataUtil
participant LogUtil
participant SLF4JLogger
ExceptionUtil->>LogUtil: logAtLevel(level, message, throwable message, throwable)
PerfDataUtil->>LogUtil: isEnabled(level)
LogUtil->>SLF4JLogger: call matching isXEnabled()
PerfDataUtil->>LogUtil: logAtLevel(level, formatted error, arguments)
LogUtil->>SLF4JLogger: call matching error/warn/info/trace/debug method
Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #3527 +/- ##
============================================
+ Coverage 78.43% 78.46% +0.02%
+ Complexity 3611 3606 -5
============================================
Files 697 698 +1
Lines 24108 24106 -2
Branches 3994 3989 -5
============================================
+ Hits 18909 18914 +5
+ Misses 2997 2995 -2
+ Partials 2202 2197 -5
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
PerfDataUtil.handleErrorandExceptionUtil.logAtLeveleach carried their own five-wayLogLevelswitch. This hoists the dispatch into a newoshi.util.LogUtiland has both delegate to it.LogUtilTwo methods, the level-parameterized halves of classic SLF4J logging:
logAtLevel(Logger, LogLevel, String, Object...)— the shared dispatch, now varargs.isEnabled(Logger, LogLevel)— restores the capability ofLogger#isEnabledForLevelthat Avoid SLF4J 2-only Logger API in logging helpers #3432 had to drop for slf4j 1.x compatibility.ExceptionUtil.logAtLevelkeeps its exact signature and becomes a one-line delegate, sooshi-core-ffmand any downstream caller are unaffected.PerfDataUtil.handleError31 lines to 7.
isEnabledlets it keep skippingFormatUtil.formatErrorwhen the level is off, without an inline switch to do the checking.It was also double-formatting:
FormatUtil.formatErrorreturns the output ofString.format, and the result was passed throughString.formatagain with no arguments. Harmless, since the hex output contains no%, but pointless.PerfCounterQueryHandlerhad the same copy-paste and is fixed too — itsisWarnEnabledguards are left alone, since both sites log at a level known at the call site and can check it directly.forbidden-apis
Widened from
org.slf4j.event.Leveltoorg.slf4j.event.**. Checking the jars, slf4j-api 1.7.5 has noorg/slf4j/eventpackage at all, while 1.7.25 has six entries — the package arrives as a unit, so every type in it breaks the same hosts that motivated #3524 and #3525.Coverage
The level switch now lives in
oshi-common, where a cross-platform test covers all ten branches. Previously the only fully covered copy was inPerfDataUtil, reachable only on Windows CI. Local JaCoCo, before vs after:The
oshi-coreclasses are Windows-only and read 0-covered on a Mac either way; the point is the shrinking denominator.LogUtilTestuses ajava.lang.reflect.Proxyrecorder rather than SLF4J's ownSubstituteLogger, becauseSubstituteLoggingEvent.getLevel()returns the bannedorg.slf4j.event.Level. The proxy asserts the contract directly: whichLoggermethod each level dispatches to, and that arguments arrive unformatted for deferred substitution.No user-observable behavior change — the emitted message text is byte-identical.
Summary by CodeRabbit