mirror of
https://github.com/internetarchive/brozzler.git
synced 2025-05-20 07:20:22 -04:00
feat: set up structlog logging (#325)
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:
parent
69d682beb9
commit
23cee477dc
15 changed files with 421 additions and 396 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue