SimpleXMLRPCServer 모듈을 사용하여 rpc 서버를 만들고 있습니다. 서버에 요청을 보낼 때마다 연결 요청이 표시됩니다. 나중에 서버에 대한 요청을 볼 수 있도록이 출력을 일부 파일로 리디렉션하려면 어떻게해야합니까?
이것은 서버용 스크립트입니다.
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'
요청을 보낼 때마다 다음과 같은 O / P를 받게됩니다.
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 -
이 O / P를 일부 파일로 리디렉션하려면 어떻게해야합니까? 로깅 구성에서 파일 이름을 설정했지만 O / P가 거기에 가지 않습니다.
메시지는에 기록됩니다 sys.stderr
. 당신은
stderr
또는SimpleXMLRPCRequestHandler
에서 메서드 를 재정의하고 원하는 경우 log_message
사용하십시오 logging
.원래 메서드는 BaseHTTPRequestHandler.log_message
모듈에 BaseHTTPServer
있으며 다음과 같습니다.
def log_message(self, format, *args):
"""Log an arbitrary message.
This is used by all other logging functions. Override
it if you have specific logging wishes.
The first argument, FORMAT, is a format string for the
message to be logged. If the format string contains
any % escapes requiring parameters, they should be
specified as subsequent arguments (it's just like
printf!).
The client host and current date/time are prefixed to
every message.
"""
sys.stderr.write("%s - - [%s] %s\n" %
(self.address_string(),
self.log_date_time_string(),
format%args))
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다