title: Python 3: How to log SSL handshake errors from server side
body: <p>I'm using HTTPServer for a basic HTTP server using SSL. I would like to log any time a client initiates an SSL Handshake (or perhaps any time a socket is accepted?) along with any associated errors. I imagine that I'd need to extend some class or override some method, but I'm not sure which or how to properly go about implementing it. I'd greatly appreciate any help. Thanks in advance!</p>
  
  <p>Trimmed down sample code:</p>
  
  <pre><code>from http.server import BaseHTTPRequestHandler, HTTPServer
  from socketserver import ThreadingMixIn
  from threading import Thread
  import ssl
  import logging
  import sys
  
  class MyHTTPHandler(BaseHTTPRequestHandler):
      def log_message(self, format, *args):
          logger.info("%s - - %s" % (self.address_string(), format%args))
      def do_GET(self):
          self.send_response(200)
          self.end_headers()
          self.wfile.write('test'.encode("utf-8"))
  
  class ThreadedHTTPServer(ThreadingMixIn, HTTPServer):
      pass
  
  logger = logging.getLogger('myserver')
  handler = logging.FileHandler('server.log')
  formatter = logging.Formatter('[%(asctime)s] %(message)s')
  handler.setFormatter(formatter)
  logger.addHandler(handler)
  logger.setLevel(logging.DEBUG)
  
  server = ThreadedHTTPServer(('', 443), MyHTTPHandler)
  server.socket = ssl.wrap_socket (server.socket, keyfile='server.key', certfile='server.crt', server_side=True, cert_reqs=ssl.CERT_REQUIRED, ca_certs='client.crt')
  Thread(target=server.serve_forever).start()
  
  try: 
      quitcheck = input("Type 'quit' at any time to quit.\n")
      if quitcheck == "quit":
          server.shutdown()
  except (KeyboardInterrupt) as error:
      server.shutdown()
  </code></pre>