Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4234054
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T02:18:01+00:00 2026-05-21T02:18:01+00:00

I found a recipe do log activities of an XML-RPC server at http://code.activestate.com/recipes/496700-logging-simplexmlrpcserver/ The

  • 0

I found a recipe do log activities of an XML-RPC server at http://code.activestate.com/recipes/496700-logging-simplexmlrpcserver/

The problem that I’m having is I want to reuse the LoggingSimpleRPCRequestHandler (i.e import it) but I don’t know how to correctly set the ‘logger’ variable. The idea is that

This works (LoggedWork.py):

from SimpleXMLRPCServer import SimpleXMLRPCServer, SimpleXMLRPCRequestHandler
from SocketServer import ThreadingMixIn

import os, sys
import logging

class RemoteObject:    
    def return10(self):
        return 10

class LoggingSimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): 
    """Overides the default SimpleXMLRPCRequestHander to support logging.  Logs
    client IP and the XML request and response.
    """    

    def do_POST(self):
        clientIP, port = self.client_address
    # Log client IP and Port

        logger.info('Client IP: %s - Port: %s' % (clientIP, port))
        try:
            # get arguments
            data = self.rfile.read(int(self.headers["content-length"]))
            # Log client request
        logger.info('Client request: \n%s\n' % data)

            response = self.server._marshaled_dispatch(
                    data, getattr(self, '_dispatch', None)
                )
        # Log server response
            logger.info('Server response: \n%s\n' % response)

    except: # This should only happen if the module is buggy
            # internal error, report as HTTP server error
            self.send_response(500)
            self.end_headers()
        else:
            # got a valid XML RPC response
            self.send_response(200)
            self.send_header("Content-type", "text/xml")
            self.send_header("Content-length", str(len(response)))
            self.end_headers()
            self.wfile.write(response)

            # shut down the connection
            self.wfile.flush()
            self.connection.shutdown(1)

class ThreadingServer(ThreadingMixIn, SimpleXMLRPCServer):
    pass

if __name__ == "__main__":

    logger = logging.getLogger('Log')
    hdlr = logging.FileHandler('Log.log')
    formatter = logging.Formatter("%(asctime)s  %(levelname)s  %(message)s")
    hdlr.setFormatter(formatter)
    logger.addHandler(hdlr)
    logger.setLevel(logging.INFO)


    serveraddr = ('', 10001)
    srvr       = ThreadingServer(serveraddr, LoggingSimpleXMLRPCRequestHandler)    
    srvr.register_instance(RemoteObject())
    srvr.register_introspection_functions()

    srvr.serve_forever()

and this doesn’t (LoggedBroken.py):

from SimpleXMLRPCServer import SimpleXMLRPCServer, SimpleXMLRPCRequestHandler
from SocketServer import ThreadingMixIn
from  LoggingSimpleXMLRPCRequestHandler import  LoggingSimpleXMLRPCRequestHandler
import os, sys
import logging

class RemoteObject:    
    def return10(self):
        return 10

class ThreadingServer(ThreadingMixIn, SimpleXMLRPCServer):
    pass

if __name__ == "__main__":

    logger = logging.getLogger('Log')
    hdlr = logging.FileHandler('Log.log')
    formatter = logging.Formatter("%(asctime)s  %(levelname)s  %(message)s")
    hdlr.setFormatter(formatter)
    logger.addHandler(hdlr)
    logger.setLevel(logging.INFO)


    serveraddr = ('', 10001)
    srvr       = ThreadingServer(serveraddr, LoggingSimpleXMLRPCRequestHandler)    
    srvr.register_instance(RemoteObject())
    srvr.register_introspection_functions()

    srvr.serve_forever()

If there is a better way to do, please advise. Thank you.

-k

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T02:18:02+00:00Added an answer on May 21, 2026 at 2:18 am

    Ok, I haven’t properly read you code. Now I see that in this structure it is impossible to do what I proposed. What I would do here is to prepare custom logger at the module level and retrieve it by name in LoggingSimpleXMLRPCRequestHandler.

    Your are doing part of it in “main”: configuring the logger with name ‘Log’. Then retrieve that logger in LoggingSimpleXMLRPCRequestHandler:

    class LoggingSimpleXMLRPCRequestHandler(SimpleXMLRequestHandler):
        def __init__(self):
            self.logger = logging.getLogger('Log')
    

    and in LoggingSimpleXMLRPCRequestHandler methods use self.logger instead of logger.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I looked online and found some SO discussing and ActiveState recipes for running some
I am using this class in MSVC++ 2010 Express: http://www.codeproject.com/KB/recipes/HMACSHA1class.aspx . I am running
Found some old code, circa VS 2003. Now I have just VS 2008 (SP1)
Found a piece of code today, that I find a little smelly... TMyObject.LoadFromFile(const filename:
Found two libraries Rebex ( www.rebex.net ) and QuikSoft ( www.quiksoft.com ) any comments
I'm trying to use the recipe found in a comment on Extract filename and
Some time ago, reading the App Engine Cookbook, I found this recipe based on
Here I found a very good recipe of how to calculate a sequence of
I have 2 activities. Each extends Activity. I tried all ways I found here,
Quick question: I've started placing StackOverflow Q&A and recipe links in my code comments

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.