From 9dff382e4730ce5fe70f52090006f1262fab4ed7 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Thu, 20 Feb 2014 14:19:22 -0800 Subject: [PATCH] server: Log source-requests and errors --- package_cache/server.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/package_cache/server.py b/package_cache/server.py index 42c2eb9..2dfbc1e 100644 --- a/package_cache/server.py +++ b/package_cache/server.py @@ -17,6 +17,7 @@ import calendar as _calendar import email.utils as _email_utils +import logging as _logging import mimetypes as _mimetypes import os as _os import urllib.error as _urllib_error @@ -25,6 +26,9 @@ import urllib.request as _urllib_request from . import __version__ +LOG = _logging.getLogger(__name__) + + class InvalidFile (ValueError): def __init__(self, url): super(InvalidFile, self).__init__('invalid file {!r}'.format(url)) @@ -81,13 +85,16 @@ class Server (object): source_url = source.rstrip('/') + url try: self._get_file(url=source_url, path=path) - except _urllib_error.HTTPError: + except _urllib_error.HTTPError as e: + LOG.warn('error getting {}: {} {}'.format( + source_url, e.code, e.reason)) if i == len(self.sources) - 1: raise else: return def _get_file(self, url, path): + LOG.info('GET {}'.format(url)) with self.opener.open(url) as response: last_modified = response.getheader('Last-Modified', None) content_length = int(response.getheader('Content-Length')) @@ -101,6 +108,7 @@ class Server (object): if last_modified: mtime = _calendar.timegm(_email_utils.parsedate(last_modified)) _os.utime(path=path, times=(mtime, mtime)) + LOG.info('got {}'.format(url)) def _serve_file(self, path, environ, start_response): headers = { -- 2.26.2