frr icon indicating copy to clipboard operation
frr copied to clipboard

tools: add logfmt option for frr-reload.py

Open gtataranni opened this issue 1 year ago • 3 comments

Add the option of printing logs in logfmt format. Adopt f-string for printing log message, so that appropriate formatting can be applied.

Additional machine readable information can be printed via the extra argument. Example:

log.debug("exit context"), extra={"line": line, "ctx_keys": ctx_keys})
# ts=2024-09-10T16:10:54+02:00 level=DEBUG msg="exit context" line=exit ctx_keys=['interface t4_15867']
log.error(f"Failed to execute command {' '.join(cmd)}", extra={"cmd": cmd})
# ts=2024-09-10T16:17:07+02:00 level=ERROR msg="Failed to execute command foo bar" cmd=['foo', 'bar']

gtataranni avatar Sep 11 '24 11:09 gtataranni

What is the real case it would be helpful?

ton31337 avatar Sep 11 '24 19:09 ton31337

What is the real case it would be helpful?

This is useful for integrating with observability stacks, as logfmt is a common format for machine-readable logs. It enhances log parsing and visualization in tools like Prometheus and Grafana. We might consider using the logfmter library for a more standardized implementation. If we prefer using the library, I'll be happy to replace my implementation with that.

gtataranni avatar Sep 12 '24 16:09 gtataranni

IMO it's better without 3rd party libraries in this place as it might complicate things (installing).

Two bullets to solve still regarding this PR:

  • Please separate completely this PR into separate commits (logfmt-related, and string formatting);
  • And make sure to apply frrbot (black) formatting to your code (each commit separately).

ton31337 avatar Sep 13 '24 07:09 ton31337

ci:rerun CI stuck

ton31337 avatar Sep 23 '24 08:09 ton31337

@ton31337 Changes done, please review

gtataranni avatar Jan 13 '25 10:01 gtataranni

CI:rerun

mwinter-osr avatar Feb 05 '25 13:02 mwinter-osr