bin/ci: Add StructuredLogger to improve log handling
authorGuilherme Gallo <guilherme.gallo@collabora.com>
Fri, 14 Apr 2023 19:30:27 +0000 (16:30 -0300)
committerMarge Bot <emma+marge@anholt.net>
Wed, 19 Apr 2023 14:36:37 +0000 (14:36 +0000)
commiteb1945c3d9c84fbce6b4b93d43ad62ab56e025d9
treed7f1f1e2c25b89a376d3ffd036de5f421754de25
parent0ac3824922283d2604e87773dc2579b2b73f3a25
bin/ci: Add StructuredLogger to improve log handling

This commit introduces the StructuredLogger module, which provides a
robust and flexible logging utility supporting multiple data formats
(CSV, JSON, and YAML). By incorporating this module into our CI system,
we enhance our log management capabilities, making it easier to:

1. Monitor and analyze logs: The StructuredLogger is a dict-like data
   abstraction which autosaves into a structured data file, whenever it
   is updated. With this file, one can easily know specifics of the job
   execution without having to grep it in the traces logs or exploring
   the job artifacts. The autosave feature makes it useful even when the
   CI job fails unexpectedly, since the partial dict is always written
   back to the disk.
2. Maintain data integrity: The module includes context managers for
   file locking and editing log data, ensuring data integrity and
   preventing race conditions.
3. Support multiple formats: With built-in support for CSV, JSON, and
   YAML formats, this module caters to a wide range of use cases and
   user preferences.
4. Increase maintainability: The modular design of the StructuredLogger
   and its corresponding strategies simplifies maintenance and allows
   for seamless integration of additional formats in the future.

Signed-off-by: Guilherme Gallo <guilherme.gallo@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22500>
bin/ci/structured_logger.py [new file with mode: 0644]
bin/ci/test/test_structured_logger.py [new file with mode: 0644]