Add support for nested fields in log entries and JSON marshalling

This commit introduces the ability to handle nested fields within log entries.
The  file has been updated with a  function
that transforms flat keys with a : delimiter (e.g., obj:foo) into nested
JSON objects (e.g., ).

The  file includes new test cases to verify that:
- Nested fields are correctly unmarshalled from string representations.
- Nested fields are correctly marshalled into JSON objects.

This enhancement allows for more structured and organized metadata within log entries.
This commit is contained in:
Dan Jones 2026-02-10 16:13:39 -06:00
commit c4e864afa5
2 changed files with 34 additions and 0 deletions

View file

@ -125,6 +125,14 @@ func TestEntryUnmarshal(t *testing.T) {
[]Meta{{"me", json.RawMessage(`{"name":"Dan","coder":true}`)}},
nil,
},
{
"nested-field",
"@begin " + whens + " - A Title\n@me:name Dan\n@me:coder true @end",
"A Title",
when,
[]Meta{{"me:name", "Dan"}, {"me:coder", true}},
nil,
},
{
"json-field",
"@begin " + whens + " - Some Guy\n" + `@json {"name":"Dan","coder":true} @end`,
@ -209,6 +217,8 @@ func TestEntryJsonMarshal(t *testing.T) {
{"obj-field", "A Title", when, []Meta{{"obj", json.RawMessage(`{"foo":"bar","title":"Sub-title"}`)}}, `{"title":"A Title","date":"` + whens + `","obj":{"foo":"bar","title":"Sub-title"}}`, nil},
{"date-field", "A Title", when, []Meta{{"when", when.Add(time.Hour)}}, `{"title":"A Title","date":"` + whens + `","when":"` + when.Add(time.Hour).Format(time.RFC3339) + `"}`, nil},
{"json-field", "A Title", when, []Meta{{"json", json.RawMessage(`{"age": 41, "cool": true, "name": "Jim"}`)}}, `{"title":"A Title","date":"` + whens + `","age":41,"cool": true, "name": "Jim"}`, nil},
{"nested-field", "A Title", when, []Meta{{"obj:foo", "bar"}, {"obj:title", "Sub-title"}}, `{"title":"A Title","date":"` + whens + `","obj":{"foo":"bar","title":"Sub-title"}}`, nil},
{"double-nested-field", "A Title", when, []Meta{{"obj:foo", "bar"}, {"obj:me:name", "Dan"}, {"obj:me:age", 27}}, `{"title":"A Title","date":"` + whens + `","obj":{"foo":"bar","me":{"name":"Dan","age":27}}}`, nil},
}
for _, tt := range tests {