Package rrlog :: Module xmlrpc
[hide private]
[frames] | no frames]

Source Code for Module rrlog.xmlrpc

  1   
  2  #Copyright (c) 2007 
  3  #        Ruben Reifenberg, Germany, 07381. 
  4  #    All rights reserved. 
  5  # 
  6  #Redistribution and use in source and binary forms, with or without 
  7  #modification, are permitted provided that the following conditions 
  8  #are met: 
  9  #1. Redistributions of source code must retain the above copyright 
 10  #   notice, this list of conditions and the following disclaimer as 
 11  #   the first lines of this file unmodified. 
 12  #2. Redistributions in binary form must reproduce the above copyright 
 13  #   notice, this list of conditions and the following disclaimer in the 
 14  #   documentation and/or other materials provided with the distribution. 
 15  # 
 16  # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 
 17  # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 18  # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 19  # ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 
 20  # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
 21  # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
 22  # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
 23  # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
 24  # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
 25  # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
 26  # SUCH DAMAGE. 
 27   
 28   
 29  """ 
 30  @summary: 
 31  The client (i.e.application) side of an XMLRPC log connection. 
 32  @author: Ruben Reifenberg 
 33  """ 
 34   
 35  from xmlrpclib import ServerProxy, Error, Binary 
 36  import pickle 
 37   
 38  from rrlog import Log 
 39   
40 -class XMLRPCLogException(Exception):
41 - def __init__(self, txt, msgid):
42 """ 43 @param txt: some ascii error explanation text 44 @param msgid: msgid of the log-msg that caused the problem. 45 """ 46 Exception.__init__(self, txt+"[msgid%s]"%(msgid))
47
48 -class XMLRPCConnectionException(XMLRPCLogException):
49 """ 50 Logging went wrong because of a connection issue. 51 """ 52 pass
53 -class XMLRPCServerException(XMLRPCLogException):
54 """ 55 Logging went wrong because the server had a problem. 56 """ 57 pass
58
59 -def loglog(msg, cat=""):
60 """ 61 Deactivated, activate for debugging only. 62 Here does the log logging itself. 63 """ 64 pass
65 #print "log:%s %s"%(cat,msg) 66
67 -def connect(host, ports):
68 for port in ports: 69 server = ServerProxy("http://%s:%s"%(host,port)) 70 try: 71 clientId = server.addClient() 72 except Exception,e: 73 loglog("Connect: no server at port%s:%s"%(port, e)) 74 else: 75 loglog("Found server at %s/%s; got clientId=%s."%(host, port, clientId)) 76 return server, clientId 77 raise Exception("no server at %s%s"%(host,str(ports)))
78 79 80 81 82
83 -class LogServerProxy(object):
84 """ 85 First method call must be addClient, 86 since this establishes the server connection. 87 """
88 - def __init__(self, host, ports):
89 """ 90 """ 91 self.host = host 92 self.ports = ports
93
94 - def addClient(self):
95 """ 96 Does the connection to the server. 97 """ 98 self.server, clientId = connect(self.host,self.ports) 99 return clientId
100 101
102 - def log(self, pid, clientid, msgid, msg, special, cat, path, tblen, cfunc):
103 try: 104 ok = self.server.log( 105 Binary(pickle.dumps( 106 { 107 "pid":pid, 108 "clientid":clientid, 109 "msgid":msgid, 110 "msg":msg, 111 "special":special, 112 "cat":cat, 113 "path":path, 114 "tblen":tblen, 115 "cfunc":cfunc, 116 } 117 )), 118 ) 119 except Exception, e: 120 raise XMLRPCConnectionException("%s"%(e),msgid=msgid) 121 else: 122 if ok != "": 123 raise XMLRPCServerException(ok,msgid=msgid)
124 125 126 127
128 -def createClientLog(host, ports, errorHandler=None, traceOffset=0, stackMax=5, extractStack=True, seFilesExclude=None):
129 """ 130 convenience method 131 """ 132 return Log( 133 server = LogServerProxy(host, ports), 134 traceOffset=traceOffset, 135 stackMax = stackMax, 136 errorHandler=errorHandler, 137 seFilesExclude=seFilesExclude, 138 extractStack=extractStack, 139 )
140