Why:
Ensures high-performance JSON emission can comply with ECS (Elastic Common
Schema) requirements where numerical zero values should often be omitted
rather than emitted as '0'.
Impact:
Adds a new property() parameter 'omitIfZero' that affects templates using
format='jsonf' and dataType='number'. No change to existing templates.
Before/After:
Previously, numerical properties in jsonf mode always emitted their value
(e.g., '"field":0'); with this change, they can be completely omitted.
Technical Overview:
- Extended templateEntry options in template.h with bOmitIfZero bitfield.
- Updated template.c to parse the 'omitifzero' binary parameter.
- Implemented omission logic in tplJsonRenderValue (template.c) and
jsonField (runtime/msg.c).
- Standardized memory safety by using the project-standard CHKmalloc()
macro for all es_str2cstr() allocations and other memory checks.
- Standardized error handling by replacing explicit gotos with the
FINALIZE; macro across affected areas.
- Formatted modified files using devtools/format-code.sh for full
compliance with project style rules.
- Registered tests/json-omitifzero.sh following the "Define at Top,
Distribute Unconditionally, Register Conditionally" pattern.
Issue: https://github.com/rsyslog/rsyslog/issues/6176
With the help of AI-Agents: Antigravity
We want easy nested JSON to match common schemas (e.g., Elastic ECS)
without external processors. This introduces an opt-in mode so existing
jsonf users keep exact behavior while enabling structured output when
requested.
Impact: No change unless option.jsonftree is enabled. With jsonftree,
dotted outnames render as nested objects; empty containers are skipped.
On name collisions (object vs value), we fall back to flat rendering.
Before: jsonf always emitted flat name/value pairs, even for dotted
outnames. After: jsonf remains flat by default; enabling jsonftree makes
"host.hostname" and "host.ip" render as {"host":{"hostname":...,"ip":...}}.
Technically, we add option.jsonftree to templates. When set, we lazily
build a per-template JSON tree (tplJsonNode) from dotted segments and
render it in one pass, reusing existing jsonf formatting for leaves.
The tree state is tracked on the template and freed on template delete.
Config parsing enforces mutual exclusivity among sql, stdsql, json,
jsonf, and jsonftree. Constants record bJSONf to reuse serialized
fragments. Tests cover nested output and pure-json cases using
option.jsonftree.
This commit applies the new canonical formatting style using `clang-format` with custom settings (notably 4-space indentation), as part of our shift toward automated formatting normalization.
⚠️ No functional changes are included — only whitespace and layout modifications as produced by `clang-format`.
This change is part of the formatting modernization strategy discussed in:
https://github.com/rsyslog/rsyslog/issues/5747
Key context:
- Formatting is now treated as a disposable view, normalized via tooling.
- The `.clang-format` file defines the canonical style.
- A fixup script (`devtools/format-code.sh`) handles remaining edge cases.
- Formatting commits are added to `.git-blame-ignore-revs` to reduce noise.
- Developers remain free to format code however they prefer locally.
The new "datatype" and "onEmpty" template options permits to
generate non-string data rather easily. It works together with
jsonf formatting, which is what people should use nowadays.
closes https://github.com/rsyslog/rsyslog/issues/2827
This enables easy JSON generation via template.
This commit also corrects an issue with the constant "jsonf"
format. That was recently added, and the implementation problem
only became visible when used inside a larger json object. No
officially released code is affected, thought - so it rellay
is just a side-note.
closes https://github.com/rsyslog/rsyslog/issues/2347
We could not reference mixed or upper case variables properly prior to
this change, as they were always lowercased before references were
pulled.
The new "option.casesensitive" for templates allows folks to turn on
variable name reference case sensitivity on a template by template
basis.
Pads a string with spaces up to toChar field if string is shorter, if
string is equal then nothing is done and if string is longer then it
gets truncated.