How can I save the output from the console like
"192.168.1.1 - - [18/Aug/2014 12:05:59] code 404, message File not found"
to a file?
Here is the code:
import SimpleHTTPServer
import SocketServer
PORT = 1548
Handler = SimpleHTTPServer.SimpleHTTPRequestHandler
httpd = SocketServer.TCPServer(("", PORT), Handler)
print "serving at port", PORT
httpd.serve_forever()
BaseHTTPRequestHandler.log_message()
prints all log messages by writing tosys.stderr
. You have two choices:1) Continue using
BaseHTTPRequestHandler.log_message()
, but change the value ofsys.stderr
:2) Create a new
xxxRequestHandler
class, replacing.log_message()
:I have used BaseHTTPServer instead of SimpleHTTPServer.
There you go: