From: W. Trevor King Date: Thu, 20 Feb 2014 22:19:22 +0000 (-0800) Subject: server: Log source-requests and errors X-Git-Tag: v0.1~13 X-Git-Url: http://git.tremily.us/?p=package-cache.git;a=commitdiff_plain;h=9dff382e4730ce5fe70f52090006f1262fab4ed7 server: Log source-requests and errors --- 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 = {