[Misc] Fix logging best practices violations in the rendering modules - #397
Merged
Conversation
* Do not print a stack trace in a warning: RenderingContextStore was passing the exception as the trailing SLF4J argument, which logs a full stack trace. Log the root cause message instead. * Use parameterized logging instead of string concatenation in IconTransformation, and log the root cause rather than the direct message. * Surround log parameters with brackets: the trailing placeholder of the MacroTransformation debug message was not wrapped. * Log the identifying parameter (macro id, syntax, resource type) in the error messages that previously logged only a bare sentence plus a stack trace. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Jira URL
N/A —
[Misc]commit, mechanical code-quality fixes that do not warrant a JIRA issue.Changes
Description
Audit of every logging call site under
src/main/java(33 of them) against theLogging Best Practices,
and fix the violations found.
Do not print a stack trace in a warning.
RenderingContextStorewas passing the exception asthe trailing SLF4J argument, which SLF4J interprets as a throwable and logs as a full stack trace.
Stack traces are reserved for
error; logExceptionUtils.getRootCauseMessage()instead.Use the parameterized SLF4J signature instead of string concatenation.
IconTransformationwas building its message with
+, and usede.getMessage()rather than the root cause message.Surround parameters with
[]. The trailing placeholder of theMacroTransformationdebugmessage was bare (
: {}). Reformatting it also brought that line back under 120 characters (itwas 126).
Log as much information as possible. Four
errorcalls logged only a bare sentence plus astack trace, with no way to tell which macro / syntax / resource type failed:
MacroTransformation#prepare(Block)MacroTransformation#prepare(Block, Syntax)DefaultResourceReferenceParser#parseDefaultXHTMLLinkRenderer#getXHTMLLinkTypeRendererClarifications
MacroTransformation#prepare(Block)the syntax is logged rather than the block itself: thatcatchhandles aStackOverflowError, andAbstractBlock#toString()recurses through allchildren, so rendering the block could overflow the stack again while building the message.
components inject
Loggerand non-components useprivate static final Logger LOGGER; nodouble-bracket cases (the
Blockparameters inPutFootnotesMacrorender asCompositeBlock:[…],so the leading
[is not doubled); the fourBlockStateChainingListenerdebug(msg, new IllegalStateException())calls are already guarded byisDebugEnabled().XWikiSerializer2usesjava.util.logging.Loggerinstead of SLF4J. The field is never actuallyused to log, but it is exposed through public
getLogger()/setLogger(), so replacing it is abreaking API change needing deprecation, a legacy re-add and a Revapi ignore.
"Failed to initialize the default WikiModel implementation"(BlockNoteRenderer,AttachmentXHTMLImageTypeRenderer) is inaccurate — nothing is initialized, it is aComponentLookupExceptionfrom looking up whicheverWikiModelis registered, and there is no"default implementation". The identical wording exists in xwiki-platform, so changing it here
only would desynchronize the two.
Cause: [{}]in most places,Cause [{}].inListenerRegistry,Root reason [{}]inDefaultTransformationManager). Purely cosmetic andnot a rule breach.
Screenshots & Video
N/A — no UI change.
Executed Tests
All four modules
SUCCESS— tests, Checkstyle and JaCoCo all green.Expected merging strategy
masteronly.🤖 Generated with Claude Code