feat: S14.09 per-message structured data (SolidSyslog_LogWithSd) (#560)#561
Conversation
) Add SolidSyslog_LogWithSd(handle, message, sd, sdCount) — attaches caller-built SD-ELEMENTs to a single Log call. SolidSyslog_Log becomes exactly LogWithSd(h, m, NULL, 0), so there is one formatting path. SolidSyslogMessage is unchanged (per-message SD is a call argument). MessageFormatter_Format gains the per-message array; FormatStructuredData emits the per-instance (config) SDs first, then the per-message array, into the one shared SolidSyslogSdElement, with NILVALUE only when neither produces an element (FormatSdElements helper DRYs the loop). A NULL array with nonzero count is reported (new SOLIDSYSLOG_ERROR_LOG_INCONSISTENT_SD, BAD_ARGUMENT) and treated as zero so the message still logs — mirroring the Create-time InstallStructuredData guard. Tests: emit, base-before-per-message ordering, empty-per-message keeps the base set, per-message values escaped (injection-proof, asserted on the raw frame), and the NULL-with-count guard. Worked example + oracle BDD + guide are S14.10. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Having SolidSyslog_Log call SolidSyslog_LogWithSd gave LogWithSd exactly one internal reference, which cppcheck-misra flags as 8.7 (external linkage used in one TU) — the public API is genuinely called only from integrator code the analysis set can't see. Rather than add the project's first active 8.7 suppression (D.014 retired the last), both public functions now delegate to a static SolidSyslog_DoLog holding the shared validation/guard/format/buffer body, matching the file's existing thin-public-over-static-helper pattern. Named DoLog (not Emit) — 'emit' is already taken in OriginSd for writing one SD piece and is heavily used in prose, while _Do<Operation> is the established 'real impl behind the public op' idiom (LwipRawTcpStream_Do*). Also: CLAUDE.md SolidSyslog.h row documents LogWithSd; misra_suppressions.txt 11.8 line drift renumbered (SolidSyslog.c +6, MessageFormatter.c +9), verified exit 0 against CI's --addon=misra command. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
A NULL element inside an Sd array (per-message or config) dereferenced through the unguarded SolidSyslogStructuredData_Format dispatch and crashed; nothing tested it (create-time relied only on the SolidSyslogNullSd convention). Guard the shared MessageFormatter_FormatSdElements loop so a conditionally-absent (NULL) SD is skipped and the message still emits — the per-message array is caller input at the call site and must not crash the library. Tests: NULL element skipped in both the per-message and config arrays, plus NULL-array-with- count still emits NILVALUE without crashing (the emit side of the existing report-only guard test). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (10)
📝 WalkthroughWalkthroughThis PR implements ChangesPer-Message Structured Data Feature
Sequence DiagramsequenceDiagram
participant Caller
participant SolidSyslog_LogWithSd
participant SolidSyslog_DoLog
participant SolidSyslogMessageFormatter_Format
participant Formatter
Caller->>SolidSyslog_LogWithSd: handle, message, sd[], sdCount
SolidSyslog_LogWithSd->>SolidSyslog_DoLog: forward with sd, sdCount
SolidSyslog_DoLog->>SolidSyslog_DoLog: validate (sdCount>0 && sd==NULL → error)
SolidSyslog_DoLog->>SolidSyslogMessageFormatter_Format: handle, message, context, messageSd, messageSdCount
SolidSyslogMessageFormatter_Format->>Formatter: emit base SD (context->Sd)
SolidSyslogMessageFormatter_Format->>Formatter: emit per-message SD (messageSd[])
Formatter-->>SolidSyslog_DoLog: RFC 5424 frame with all SD
Estimated Code Review Effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly Related Issues
Possibly Related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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 |
☀️ Quality Summary 🚦 build-linux-gcc: 100% successful (✔️ 1519 passed) Created by Quality Monitor v1.14.0 (#f3859fd). More details are shown in the GitHub Checks Result. |
Closes #560.
The per-message-attachment wave of E14 — caller-built SD-ELEMENTs on individual
Logcalls, combined with the per-instance base set. The authoring foundation (S14.01–08) has landed; this delivers the headline feature.API
SolidSyslog_LogWithSd(handle, message, sd, sdCount)—sdis an array ofSolidSyslogStructuredData*(same type asSolidSyslogConfig.Sd[]).SolidSyslog_Log(h, m)is exactlyLogWithSd(h, m, NULL, 0).SolidSyslogMessageis unchanged (per-message SD is a call argument, not message state).Behaviour
SolidSyslogSdElement; NILVALUE only when neither writes.SOLIDSYSLOG_ERROR_LOG_INCONSISTENT_SD, BAD_ARGUMENT) and treated as zero; a NULL element inside the array is skipped. Either way the message still emits — no crash. (The dispatch never null-guarded, and neither array had a NULL-element test; the guard lives in the sharedFormatSdElementsloop so config arrays are covered too.)Implementation note
LogandLogWithSdboth delegate to a staticSolidSyslog_DoLograther thanLogcallingLogWithSddirectly — that would giveLogWithSdone internal reference and trip MISRA 8.7 (public API, external callers invisible to the analysis set). Keeps the project's zero active 8.7 suppressions (D.014).Verification
debug: 1482 tests.BddTargetTests: 66/66. clang-format clean; cppcheck-MISRA exit 0 (verified against CI's exact--addon=misracommand).Reentrancy (for the S14.10 guide)
A custom SD that carries call-specific data reads it via
selfat Format time; don't share one such object, mutated, across concurrentLogcalls — use a per-call-site instance. Immutable/static custom SDs are unaffected.Deferred → S14.10 (#549)
Worked custom-SD example, oracle round-trip BDD, and the integrator-guide prose. Closes E14.
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
SolidSyslog_LogWithSd()API to attach structured data directly to individual log messages.Bug Fixes
Documentation
Tests