feat(template-st): log StringTemplate compile/runtime errors via SLF4J #3708
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.
Why
StringTemplate v4 defaults to
ErrorManager.DEFAULT_ERROR_LISTENER, whichwrites compile-time and runtime diagnostics directly to stderr. In most
Spring-based deployments the process stderr stream is either discarded or
treated as an unstructured blob that never reaches Logstash/Grafana, making
template failures virtually invisible at run-time.
Issue #3604 “PromptTemplate should configure error reporting in String
Template” highlighted this gap and requested a way to surface those
messages through the conventional SLF4J pipeline. This commit fulfils that
request and aligns error handling with the rest of the framework logging
strategy.
What
Slf4jStErrorListener– newSTErrorListenerimplementation thatdelegates
compileTimeError,runTimeError,IOError, andinternalErrorevents to theLoggerofStTemplateRenderer.StTemplateRendererSTGroupper render operation and registers theSLF4J listener so every template instance receives structured logging.
malformedTemplateShouldLogErrorViaSlf4jwhichListAppenderto capture log events.ERRORlog entry andthat nothing is emitted to stderr.
behaviour-identical.
StTemplateRendererto mention the newerror-reporting mechanism.
How
When
createST(String template)is invoked, the renderer now:STGroupwith the configured delimiters.Slf4jStErrorListenerinstance on the group.STtemplate from that group.Because the listener is stateless and threads only interact with it via the
SLF4J facade, the change is thread-safe and produces no additional
allocation hot-spots beyond the lifetime of the template rendering call.
Impact
application logs with timestamps, context, and stack traces, making them
searchable and monitorable.
validation semantics remain untouched. Projects depending on
StTemplateRendererrequire no code changes.dependencies.
Migration Notes
No migration steps are required. Applications will automatically benefit
from structured error logging after updating to the version that includes
this commit.
References
String Template”.
logging conventions.
Signed-off-by: [email protected]