feat: set up structlog logging (#325)
Some checks are pending
Publish Artifacts / Build distribution 📦 (push) Waiting to run
Python Formatting Check / formatting (push) Waiting to run

This ports the logging from `logging` to `structlog`. This updates
all of the logger instantiations along with all of the places
`logging` was called. Data that was being inlined into log statements
has been broken out so that it's now structured arguments to the
log statements instead.
This commit is contained in:
Misty De Méo 2025-02-24 16:31:09 -08:00 committed by GitHub
parent 69d682beb9
commit 23cee477dc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 421 additions and 396 deletions

View file

@ -31,11 +31,14 @@ import datetime
import requests
import subprocess
import http.server
import logging
import structlog
import sys
import warcprox
logger = structlog.get_logger(logger_name=__name__)
# https://stackoverflow.com/questions/166506/finding-local-ip-addresses-using-pythons-stdlib
def _local_address():
import socket
@ -70,11 +73,19 @@ def stop_service(service):
def httpd(request):
class RequestHandler(http.server.SimpleHTTPRequestHandler):
def do_POST(self):
logging.info("\n%s\n%s", self.requestline, self.headers)
logger.info(
"RequestHandler.do_POST",
requestline=self.requestline,
headers=self.headers,
)
self.do_GET()
def do_GET(self):
logging.info("\n%s\n%s", self.requestline, self.headers)
logger.info(
"RequestHandler.do_GET",
requestline=self.requestline,
headers=self.headers,
)
if self.path == "/site5/redirect/":
self.send_response(303, "See other")
self.send_header("Connection", "close")
@ -270,7 +281,7 @@ def test_proxy_non_warcprox(httpd):
def do_HEAD(self):
if not hasattr(self.server, "requests"):
self.server.requests = []
logging.info("%s %s", self.command, self.path)
logger.info("%s %s", self.command, self.path)
self.server.requests.append("%s %s" % (self.command, self.path))
response = urllib.request.urlopen(self.path)
self.wfile.write(
@ -292,7 +303,7 @@ def test_proxy_non_warcprox(httpd):
def do_WARCPROX_WRITE_RECORD(self):
if not hasattr(self.server, "requests"):
self.server.requests = []
logging.info("%s %s", self.command, self.path)
logger.info("%s %s", self.command, self.path)
self.send_error(400)
proxy = http.server.HTTPServer(("localhost", 0), DumbProxyRequestHandler)
@ -826,7 +837,7 @@ def test_warcprox_outage_resiliency(httpd):
try:
stop_service("warcprox")
except Exception as e:
logging.warning("problem stopping warcprox service: %s", e)
logger.warning("problem stopping warcprox service: %s", exc_info=True)
# queue the site for brozzling
brozzler.new_site(frontier, site)