frr
frr copied to clipboard
tools: add logfmt option for frr-reload.py
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']
What is the real case it would be helpful?
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.
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).
ci:rerun CI stuck
@ton31337 Changes done, please review
CI:rerun