简体   繁体   中英

How to stop logging from HTTP Server

I want to stop logging for my python server since I always get this text when the localhost website is called:

[28/Oct/2021 22:58:15] code 501, message Unsupported method ('GET')
[28/Oct/2021 22:58:15] "GET /favicon.ico HTTP/1.1" 501 -

I already tried it with the logging module as you can see in my code example:

from http.server import HTTPServer, BaseHTTPRequestHandler
import logging
import threading
import logging


def server_run():
    httpd = HTTPServer(('localhost', 4443), BaseHTTPRequestHandler)
    httpd.serve_forever()
    logging.getLogger("HTTPServer").setLevel(logging.CRITICAL)
    logging.getLogger("BaseHTTPRequestHandler").setLevel(logging.CRITICAL)
    logging.getLogger("http").setLevel(logging.CRITICAL)

threading.Thread(target=server_run).start()
print("Server running")

This is not possible. At the time of this writing, the code is still using the print function to stderr instead of logging. See https://github.com/python/cpython/blob/fba3b67af47723c201fe3425cb615932970a8f28/Lib/http/server.py#L582

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM