diff options
author | Jakub Warmuz <kuba@users.noreply.github.com> | 2015-11-08 09:57:23 +0300 |
---|---|---|
committer | Jakub Warmuz <kuba@users.noreply.github.com> | 2015-11-08 09:57:23 +0300 |
commit | 0f36ed3eb3517148435fe63d702e3c867cf44406 (patch) | |
tree | 7c337ab950aa08af93b07c5c964530767d1acf41 | |
parent | d209b5ea20c2f5f35eadc304dbe5cbb85c233f4d (diff) | |
parent | 0dbb235961d224247d97f95494a46469a81c05c5 (diff) |
Merge pull request #1414 from kuba/acme-standalone-log
Logging in acme.standalone: more and not to sys.stderr.
-rw-r--r-- | acme/acme/standalone.py | 38 |
1 files changed, 29 insertions, 9 deletions
diff --git a/acme/acme/standalone.py b/acme/acme/standalone.py index 32dd5ae41..3ddb21beb 100644 --- a/acme/acme/standalone.py +++ b/acme/acme/standalone.py @@ -6,7 +6,6 @@ import logging import os import sys -import six from six.moves import BaseHTTPServer # pylint: disable=import-error from six.moves import http_client # pylint: disable=import-error from six.moves import socketserver # pylint: disable=import-error @@ -55,7 +54,20 @@ class TLSSNI01Server(TLSServer, ACMEServerMixin): def __init__(self, server_address, certs): TLSServer.__init__( - self, server_address, socketserver.BaseRequestHandler, certs=certs) + self, server_address, BaseRequestHandlerWithLogging, certs=certs) + + +class BaseRequestHandlerWithLogging(socketserver.BaseRequestHandler): + """BaseRequestHandler with logging.""" + + def log_message(self, format, *args): # pylint: disable=redefined-builtin + """Log arbitrary message.""" + logger.debug("%s - - %s", self.client_address[0], format % args) + + def handle(self): + """Handle request.""" + self.log_message("Incoming request") + socketserver.BaseRequestHandler.handle(self) class HTTP01Server(BaseHTTPServer.HTTPServer, ACMEServerMixin): @@ -83,6 +95,15 @@ class HTTP01RequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): self.simple_http_resources = kwargs.pop("simple_http_resources", set()) socketserver.BaseRequestHandler.__init__(self, *args, **kwargs) + def log_message(self, format, *args): # pylint: disable=redefined-builtin + """Log arbitrary message.""" + logger.debug("%s - - %s", self.client_address[0], format % args) + + def handle(self): + """Handle request.""" + self.log_message("Incoming request") + BaseHTTPServer.BaseHTTPRequestHandler.handle(self) + def do_GET(self): # pylint: disable=invalid-name,missing-docstring if self.path == "/": self.handle_index() @@ -109,17 +130,17 @@ class HTTP01RequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): """Handle HTTP01 provisioned resources.""" for resource in self.simple_http_resources: if resource.chall.path == self.path: - logger.debug("Serving HTTP01 with token %r", - resource.chall.encode("token")) + self.log_message("Serving HTTP01 with token %r", + resource.chall.encode("token")) self.send_response(http_client.OK) self.send_header("Content-type", resource.chall.CONTENT_TYPE) self.end_headers() self.wfile.write(resource.validation.encode()) return else: # pylint: disable=useless-else-on-loop - logger.debug("No resources to serve") - logger.debug("%s does not correspond to any resource. ignoring", - self.path) + self.log_message("No resources to serve") + self.log_message("%s does not correspond to any resource. ignoring", + self.path) @classmethod def partial_init(cls, simple_http_resources): @@ -159,8 +180,7 @@ def simple_tls_sni_01_server(cli_args, forever=True): OpenSSL.crypto.FILETYPE_PEM, cert_contents)) server = TLSSNI01Server(('', int(args.port)), certs=certs) - six.print_("Serving at https://localhost:{0}...".format( - server.socket.getsockname()[1])) + logger.info("Serving at https://%s:%s...", *server.socket.getsockname()[:2]) if forever: # pragma: no cover server.serve_forever() else: |