humanlogio / humanlog

Logs for humans to read.
Apache License 2.0
730 stars 52 forks source link

flatten nested objects #114

Open aybabtme opened 4 days ago

aybabtme commented 4 days ago

right now, when a nested object is found in the input, it is sprintf("%v"). instead, it should be flattened out with .:

an input of

{"storage": {"from": "2024-10-29T05:47:00Z"}}

currently gets encoded in the kv as:

storage=map[from:2024-10-29T05:47:00Z]

but it should become

storage.from=2024-10-29T05:47:00Z
aybabtme commented 4 days ago

Another example:

input:

{"time":"2024-10-29T16:45:54.384776+09:00","level":"DEBUG","source":{"function":"github.com/humanlogio/humanlog/internal/memstorage.(*MemStorageSink).firstMatch","file":"/Users/antoine/code/src/github.com/humanlogio/humanlog/internal/memstorage/memory.go","line":243},"msg":"first match found at index","storage":{"machine.id":5089,"session.id":1730187806608637000,"i":0}}

current render (when fed into humanlog --truncate=false):

Oct 29 16:45:54 |DEBU| first match found at index storage=map[i:0 machine.id:5089 session.id:1.730187806608637e+18] source=map[file:/Users/antoine/code/src/github.com/humanlogio/humanlog/internal/memstorage/memory.go function:github.com/humanlogio/humanlog/internal/memstorage.(*MemStorageSink).firstMatch line:243]

expected render:


Oct 29 16:45:54 |DEBU| first match found at index storage.i=0 storage.machine.id=5089 storage.session.id=1.730187806608637e+18 source.file="/Users/antoine/code/src/github.com/humanlogio/humanlog/internal/memstorage/memory.go" source.function="github.com/humanlogio/humanlog/internal/memstorage.(*MemStorageSink).firstMatch" source.line=243