Skip to content

Instantly share code, notes, and snippets.

@plamentotev
Last active October 31, 2018 19:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save plamentotev/b75d3aceb43b4ca8dec58d6a9b303735 to your computer and use it in GitHub Desktop.
Save plamentotev/b75d3aceb43b4ca8dec58d6a9b303735 to your computer and use it in GitHub Desktop.
Very simple (and even more insecure) logging service. Just send POST request to PORT (8000 by default) and the service will log its body into log file
import http.server
import logging
import socketserver
logging.basicConfig(filename='messages.log', format='%(levelname)s:%(asctime)s:%(message)s', level=logging.DEBUG)
class SimpleLoggingHandler(http.server.BaseHTTPRequestHandler):
def do_POST(self):
msg = self.rfile.read(int(self.headers['Content-Length'])).decode('UTF-8')
logging.info(msg)
self.send_response(204)
self.send_header("Access-Control-Allow-Origin", "*")
self.end_headers()
PORT = 8000
logging.info("Serving at port %s", PORT)
with socketserver.TCPServer(("", PORT), SimpleLoggingHandler) as httpd:
httpd.serve_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment