Add json and zerolog writers
Ive been using kail for some time now and I find it very useful. Ive seen this open PR https://github.com/boz/kail/pull/24, and implemented this as a separate writer struct as suggested. This would also address this issue https://github.com/boz/kail/issues/31.
Ive added two writers
(a) A simple json writer enabled with the flag --json which attempts to parse json logs and if succesful, formats the output as indented json, otherwise falls back to the default behavior. Optionally, a jsonpath filter can be specified Eg --jsonpath=$.message which selected the message field. If the selected field is a string, it is formatted as plain text.
(b) A zerolog json writer enabled with the flag --zerolog, which formats json, if applicable, using the zerolog console writer, otherwise falls back to the default behavior. Ive added cli flags to customize the zero field names, if necessary. The formatted output is compact with nice colors etc.
The following cli options are added:
--json formats json logs, with optional jsonpath
--jsonpath=$.message filters json logs when --json is enabled
--zerolog formats zerolog json logs
--zerolog-timestamp-field="time"
sets the zerolog timestamp field name
--zerolog-level-field="level"
sets the zerolog level field name
--zerolog-message-field="message"
sets the zerolog message field name
--zerolog-error-field="error"
sets the zerolog error field name
Note: This would add two dependencies: github.com/yalp/jsonpath , and github.com/rs/zerolog. I believe the zerolog console writer is pretty much standalone and could be copied in without importing the full zerolog package, if that would be better.
In practice, I'm using the zerolog writer frequently, but added the basic json writer for more general use cases. zerolog assumes a flat json log structure.
I'd like to see this merged! I think the only thing missing is adding those new options to the README as well.
bump
OK, I'll take a look shortly, @terrafying.
It's been a while since i've used this actively, but happy to make updates if necessary
@johncsnyder could you rebase/rework to review?
@johncsnyder also what are your thoughts on the approach in https://github.com/boz/kail/pull/48 ?
@johncsnyder I have updated changes with other writers, but removed jsonpath change as that library is not maintained and have many issues.
@mnaser @chandanpasunoori I've not had much time recently to take a look, but thank you for pushing forward, looks good 🙏