Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何将xmlrpc服务器的日志输出重定向到某个文件_Python_Logging_Xml Rpc_Simplexmlrpcserver - Fatal编程技术网

Python 如何将xmlrpc服务器的日志输出重定向到某个文件

Python 如何将xmlrpc服务器的日志输出重定向到某个文件,python,logging,xml-rpc,simplexmlrpcserver,Python,Logging,Xml Rpc,Simplexmlrpcserver,我正在使用SimpleXMLRPCServer模块创建一个rpc服务器。每当我向服务器发送任何请求时,它都会显示连接请求。如何将此输出重定向到某个文件,以便稍后可以看到向服务器发出的请求 这是我的服务器脚本 from SimpleXMLRPCServer import SimpleXMLRPCServer from SimpleXMLRPCServer import SimpleXMLRPCRequestHandler import logging import os import string

我正在使用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'
无论何时我发出任何请求,我都会得到这样的订单-

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重定向到某个文件。我在logging config中设置了文件名,但是o/p没有进入那里

消息被写入
sys.stderr
。你也可以

  • 重定向
    stderr
    ,或
  • SimpleXMLRPCRequestHandler的子类中
    重写方法
    log\u message
    ,并在那里使用
    logging
  • 原始方法是模块
    BaseHTTPServer
    中的
    BaseHTTPRequestHandler.log_message
    ,如下所示:

    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))