Home / Companies / GitHub / Blog / Post Details
Content Deep Dive

Introducing Annotated Logger: A Python package to aid in adding metadata to logs

Blog post from GitHub

Post Details
Company
Date Published
Author
Joseph Henrich
Word Count
3,873
Language
English
Hacker News Points
-
Summary

Annotated Logger is a Python package developed by GitHub’s Vulnerability Management team to enhance logging capabilities by allowing the decoration of functions and classes for automatic logging upon completion, while offering customized logger objects with pre-added fields. The package addresses the challenges of repeatedly adding extra fields, such as deployment branch information or CVE names, to log messages in complex Python projects using Splunk. By using decorators like @annotate_logs, developers can streamline logging processes, reducing manual repetition and enabling the addition of dynamic annotations to log messages. The Annotated Logger has evolved from a simple decorator to a standalone package with features like logging iterations, runtime annotations, pre/post hooks, and plugins for custom logging behavior, all configurable via dictConfig. It offers robust type hinting support and integrates seamlessly into existing projects. The package also includes a pytest mock to facilitate testing of logged messages, ensuring that important log entries are correctly formatted and meet specified criteria.