I'm using the SimpleXMLRPCServer module to create a rpc server. Whenever i send any request to server it shows me the connection request. How can i redirect this output to some file so that i can see the request made to the server later.
this is my script for server
from SimpleXMLRPCServer import SimpleXMLRPCServer
from SimpleXMLRPCServer import SimpleXMLRPCRequestHandler
import logging
import os
import string
from subprocess import Popen,PIPE
import xmlrpclib
# Set up logging
logging.basicConfig(level=logging.DEBUG, filename = 'RPCServer.log')
class FileOperation():
'''Class to perform file operation on the Remote machine'''
def __init__(self):
self.fh = None
self.os = os #adding built-in OS module functionality
self.string = string #adding built-in String module functionality
# Restrict to a particular path.
class RequestHandler(SimpleXMLRPCRequestHandler):
rpc_paths = ('/RPC2',)
# Create server
server = SimpleXMLRPCServer(("localhost", 8000), requestHandler = RequestHandler,allow_none = True, logRequests = True)
server.register_introspection_functions()
server.register_instance(FileOperation(),allow_dotted_names = True )
# Run the server's main loop
try:
print 'Use Control-C to exit'
server.serve_forever()
except KeyboardInterrupt:
print 'Exiting'
Whenever I send any request I'll get o/p like this -
Use Control-C to exit
127.0.0.1 - - [11/Dec/2013 11:34:29] "POST /RPC2 HTTP/1.1" 200 -
127.0.0.1 - - [11/Dec/2013 11:34:30] "POST /RPC2 HTTP/1.1" 200 -
127.0.0.1 - - [11/Dec/2013 11:34:31] "POST /RPC2 HTTP/1.1" 200 -
127.0.0.1 - - [11/Dec/2013 11:34:32] "POST /RPC2 HTTP/1.1" 200 -
127.0.0.1 - - [11/Dec/2013 11:34:33] "POST /RPC2 HTTP/1.1" 200 -
127.0.0.1 - - [11/Dec/2013 11:34:34] "POST /RPC2 HTTP/1.1" 200 -
127.0.0.1 - - [11/Dec/2013 11:34:35] "POST /RPC2 HTTP/1.1" 200 -
How can i redirect this o/p to some file. I set the file name in logging config but the o/p doesn't go there
The messages are written to
sys.stderr
. You can eitherstderr
, orSimpleXMLRPCRequestHandler
override the methodlog_message
and uselogging
there if you wish.The original method is
BaseHTTPRequestHandler.log_message
in moduleBaseHTTPServer
and looks like this: