really fixed the redundant logging issue this time.
authorTony Mack <tmack@paris.CS.Princeton.EDU>
Tue, 21 Jun 2011 20:52:35 +0000 (16:52 -0400)
committerMarco Yuen <marcoy@gmail.com>
Wed, 22 Jun 2011 18:08:33 +0000 (14:08 -0400)
32 files changed:
sfa/client/sfadump.py
sfa/client/sfascan.py
sfa/client/sfi.py
sfa/managers/aggregate_manager_max.py
sfa/managers/slice_manager_pl.py
sfa/plc/api.py
sfa/plc/network.py
sfa/plc/sfa-import-plc.py
sfa/plc/sfa-nuke-plc.py
sfa/plc/sfaImport.py
sfa/rspecs/rspec_version.py
sfa/server/interface.py
sfa/server/modpython/SfaAggregateModPython.py
sfa/server/modpython/SfaRegistryModPython.py
sfa/server/modpython/SfaSliceMgrModPython.py
sfa/server/sfa-server.py
sfa/trust/auth.py
sfa/trust/certificate.py
sfa/trust/credential.py
sfa/trust/gid.py
sfa/trust/hierarchy.py
sfa/util/PostgreSQL.py
sfa/util/api.py
sfa/util/callids.py
sfa/util/componentserver.py
sfa/util/method.py
sfa/util/rspec.py
sfa/util/rspecHelper.py
sfa/util/server.py
sfa/util/sfalogging.py
sfa/util/xmlrpcprotocol.py
sfa/util/xrn.py

index 1ea1a7c..54654f8 100755 (executable)
@@ -13,7 +13,7 @@ from sfa.trust.credential import Credential
 from sfa.trust.gid import GID
 from sfa.util.record import SfaRecord
 from sfa.util.rspec import RSpec
-from sfa.util.sfalogging import sfa_logger
+from sfa.util.sfalogging import logger
 
 def determine_sfa_filekind(fn):
 
@@ -110,7 +110,7 @@ display info on input files"""
     parser.add_option("-v", "--verbose", action='count', dest='verbose', default=0)
     (options, args) = parser.parse_args()
 
-    sfa_logger().setLevelFromOptVerbose(options.verbose)
+    logger.setLevelFromOptVerbose(options.verbose)
     if len(args) <= 0:
         parser.print_help()
         sys.exit(1)
index eff17ec..b6f62e2 100755 (executable)
@@ -10,7 +10,7 @@ import pygraphviz
 from optparse import OptionParser
 
 from sfa.client.sfi import Sfi
-from sfa.util.sfalogging import sfa_logger
+from sfa.util.sfalogging import logger
 import sfa.util.xmlrpcprotocol as xmlrpcprotocol
 
 def url_hostname_port (url):
@@ -68,7 +68,7 @@ class Interface:
             key_file = client.get_key_file()
             cert_file = client.get_cert_file(key_file)
             url=self.url()
-            sfa_logger().info('issuing get version at %s'%url)
+            logger.info('issuing get version at %s'%url)
             server=xmlrpcprotocol.get_server(url, key_file, cert_file, options)
             self._version=server.GetVersion()
         except:
@@ -158,17 +158,17 @@ class SfaScan:
                 # performing xmlrpc call
                 version=interface.get_version()
                 if self.verbose:
-                    sfa_logger().info("GetVersion at interface %s"%interface.url())
+                    logger.info("GetVersion at interface %s"%interface.url())
                     if not version:
-                        sfa_logger().info("<EMPTY GetVersion(); offline or cannot authenticate>")
+                        logger.info("<EMPTY GetVersion(); offline or cannot authenticate>")
                     else: 
                         for (k,v) in version.iteritems(): 
                             if not isinstance(v,dict):
-                                sfa_logger().info("\r\t%s:%s"%(k,v))
+                                logger.info("\r\t%s:%s"%(k,v))
                             else:
-                                sfa_logger().info(k)
+                                logger.info(k)
                                 for (k1,v1) in v.iteritems():
-                                    sfa_logger().info("\r\t\t%s:%s"%(k1,v1))
+                                    logger.info("\r\t\t%s:%s"%(k1,v1))
                 # 'geni_api' is expected if the call succeeded at all
                 # 'peers' is needed as well as AMs typically don't have peers
                 if 'geni_api' in version and 'peers' in version: 
@@ -195,7 +195,7 @@ class SfaScan:
                     for (k,v) in interface.get_layout().iteritems():
                         node.attr[k]=v
                 else:
-                    sfa_logger().error("MISSED interface with node %s"%node)
+                    logger.error("MISSED interface with node %s"%node)
     
 
 default_outfiles=['sfa.png','sfa.svg','sfa.dot']
@@ -218,12 +218,12 @@ def main():
     scanner=SfaScan(left_to_right=options.left_to_right, verbose=options.verbose)
     entries = [ Interface(entry) for entry in args ]
     g=scanner.graph(entries)
-    sfa_logger().info("creating layout")
+    logger.info("creating layout")
     g.layout(prog='dot')
     for outfile in options.outfiles:
-        sfa_logger().info("drawing in %s"%outfile)
+        logger.info("drawing in %s"%outfile)
         g.draw(outfile)
-    sfa_logger().info("done")
+    logger.info("done")
 
 if __name__ == '__main__':
     main()
index 09deb3e..750d873 100755 (executable)
@@ -15,7 +15,7 @@ from lxml import etree
 from StringIO import StringIO
 from types import StringTypes, ListType
 from optparse import OptionParser
-from sfa.util.sfalogging import _SfaLogger, logging
+from sfa.util.sfalogging import info_logger
 from sfa.trust.certificate import Keypair, Certificate
 from sfa.trust.gid import GID
 from sfa.trust.credential import Credential
@@ -141,7 +141,7 @@ class Sfi:
         self.user = None
         self.authority = None
         self.hashrequest = False
-        self.logger = _SfaLogger(self.sfi_dir + 'sfi.log', level = logging.INFO)
+        self.logger = info_logger
    
     def create_cmd_parser(self, command, additional_cmdargs=None):
         cmdargs = {"list": "authority",
index 0c374b4..36afd11 100644 (file)
@@ -2,7 +2,7 @@ from sfa.util.xrn import urn_to_hrn, hrn_to_urn, get_authority
 from sfa.util.plxrn import hrn_to_pl_slicename
 from sfa.util.plxrn import hrn_to_pl_slicename
 from sfa.util.rspec import RSpec
-from sfa.util.sfalogging import sfa_logger
+from sfa.util.sfalogging import logger
 from sfa.util.config import Config
 from sfa.managers.aggregate_manager_pl import GetVersion, __get_registry_objects
 from sfa.plc.slices import Slices
@@ -38,7 +38,7 @@ def call_am_apiclient(client_app, params, timeout):
     (client_path, am_url) = Config().get_max_aggrMgr_info()
     sys_cmd = "cd " + client_path + "; java -classpath AggregateWS-client-api.jar:lib/* net.geni.aggregate.client.examples." + client_app + " ./repo " + am_url + " " + ' '.join(params)
     ret = shell_execute(sys_cmd, timeout)
-    sfa_logger().debug("shell_execute cmd: %s returns %s" % (sys_cmd, ret))
+    logger.debug("shell_execute cmd: %s returns %s" % (sys_cmd, ret))
 # save request RSpec xml content to a tmp file
 def save_rspec_to_file(rspec):
     path = RSPEC_TMP_FILE_PREFIX + "_" + time.strftime('%Y%m%dT%H:%M:%S', time.gmtime(time.time())) +".xml"
@@ -105,9 +105,9 @@ def get_rspec(api, cred, options):
         rspec = "<RSpec type=\"SFA\"> <Fault>No resource found</Fault> </RSpec>"
     else:
         comp_rspec = get_xml_by_tag(output, 'computeResource')
-        sfa_logger().debug("#### computeResource %s" % comp_rspec)
+        logger.debug("#### computeResource %s" % comp_rspec)
         topo_rspec = get_xml_by_tag(output, 'topology')
-        sfa_logger().debug("#### topology %s" % topo_rspec)
+        logger.debug("#### topology %s" % topo_rspec)
         rspec = "<RSpec type=\"SFA\"> <network name=\"" + Config().get_interface_hrn() + "\">";
         if comp_rspec != None:
             rspec = rspec + get_xml_by_tag(output, 'computeResource')
index 1d801e3..5ed2261 100644 (file)
@@ -7,7 +7,7 @@ from copy import deepcopy
 from copy import copy
 from lxml import etree
 
-from sfa.util.sfalogging import sfa_logger
+from sfa.util.sfalogging import logger
 from sfa.util.rspecHelper import merge_rspecs
 from sfa.util.xrn import Xrn, urn_to_hrn, hrn_to_urn
 from sfa.util.plxrn import hrn_to_pl_slicename
@@ -62,7 +62,7 @@ def get_serverproxy_url (server):
     try:
         return server.url
     except:
-        sfa_logger().warning("GetVersion, falling back to xmlrpclib.ServerProxy internals")
+        logger.warning("GetVersion, falling back to xmlrpclib.ServerProxy internals")
         return server._ServerProxy__host + server._ServerProxy__handler 
 
 def GetVersion(api):
index 8e15ea7..200d05c 100644 (file)
@@ -12,7 +12,7 @@ import xmlrpclib
 from sfa.util.faults import *
 from sfa.util.api import *
 from sfa.util.config import *
-from sfa.util.sfalogging import sfa_logger
+from sfa.util.sfalogging import logger
 import sfa.util.xmlrpcprotocol as xmlrpcprotocol
 from sfa.trust.auth import Auth
 from sfa.trust.rights import Right, Rights, determine_rights
@@ -106,7 +106,6 @@ class SfaAPI(BaseAPI):
 
         self.hrn = self.config.SFA_INTERFACE_HRN
         self.time_format = "%Y-%m-%d %H:%M:%S"
-        self.logger=sfa_logger()
 
     def getPLCShell(self):
         self.plauth = {'Username': self.config.SFA_PLC_USER,
@@ -340,7 +339,7 @@ class SfaAPI(BaseAPI):
             # fill in key info
             if record['type'] == 'user':
                 if 'key_ids' not in record:
-                    self.logger.info("user record has no 'key_ids' - need to import from myplc ?")
+                    logger.info("user record has no 'key_ids' - need to import from myplc ?")
                 else:
                     pubkeys = [keys[key_id]['key'] for key_id in record['key_ids'] if key_id in keys] 
                     record['keys'] = pubkeys
index 203d321..9276fb0 100644 (file)
@@ -7,7 +7,6 @@ from lxml import etree
 from xmlbuilder import XMLBuilder
 
 from sfa.util.faults import *
-#from sfa.util.sfalogging import sfa_logger
 from sfa.util.xrn import get_authority
 from sfa.util.plxrn import hrn_to_pl_slicename, hostname_to_urn
 
index 7b96c35..45386ea 100755 (executable)
@@ -28,6 +28,7 @@ from sfa.trust.trustedroot import *
 from sfa.trust.hierarchy import *
 from sfa.util.xrn import Xrn
 from sfa.plc.api import *
+from sfa.util.sfalogging import logger
 from sfa.trust.gid import create_uuid
 from sfa.plc.sfaImport import sfaImport
 
@@ -146,7 +147,7 @@ def main():
     # start importing 
     for site in sites:
         site_hrn = interface_hrn + "." + site['login_base']
-        sfa_logger().info("Importing site: %s" % site_hrn)
+        logger.info("Importing site: %s" % site_hrn)
 
         # import if hrn is not in list of existing hrns or if the hrn exists
         # but its not a site record
index 8436035..7ba6337 100755 (executable)
@@ -14,7 +14,7 @@ from optparse import OptionParser
 from sfa.trust.hierarchy import *
 from sfa.util.record import *
 from sfa.util.table import SfaTable
-from sfa.util.sfalogging import sfa_logger_goes_to_import,sfa_logger
+from sfa.util.sfalogging import logger
 
 def main():
    usage="%prog: trash the registry DB (the 'sfa' table in the 'planetlab5' database)"
@@ -25,8 +25,7 @@ def main():
    if args:
       parser.print_help()
       sys.exit(1)
-   sfa_logger_goes_to_import()
-   sfa_logger().info("Purging SFA records from database")
+   logger.info("Purging SFA records from database")
    table = SfaTable()
    table.sfa_records_purge()
    if options.clean_fs:
@@ -38,8 +37,8 @@ def main():
             path=dir+os.sep+file
             os.unlink(path)
             if not os.path.exists(path):
-               sfa_logger().info("Unlinked file %s"%path)
+               logger.info("Unlinked file %s"%path)
             else:
-               sfa_logger().error("Could not unlink file %s"%path)
+               logger.error("Could not unlink file %s"%path)
 if __name__ == "__main__":
    main()
index 238b5e1..ee34833 100644 (file)
@@ -12,7 +12,7 @@ import getopt
 import sys
 import tempfile
 
-from sfa.util.sfalogging import sfa_logger_goes_to_import,sfa_logger
+from sfa.util.sfalogging import _SfaLogger
 
 from sfa.util.record import *
 from sfa.util.table import SfaTable
@@ -52,8 +52,7 @@ def _cleanup_string(str):
 class sfaImport:
 
     def __init__(self):
-       sfa_logger_goes_to_import()
-       self.logger = sfa_logger()
+       self.logger = _SfaLogger(logfile='/var/log/sfa_import.log', loggername='importlog')
        self.AuthHierarchy = Hierarchy()
        self.config = Config()
        self.TrustedRoots = TrustedRootList(Config.get_trustedroots_dir(self.config))
index b96a765..e6cdcec 100755 (executable)
@@ -1,5 +1,5 @@
 #!/usr/bin/python
-from sfa.util.sfalogging import _SfaLogger
+from sfa.util.sfalogging import logger
 
 class RSpecVersion(dict):
 
@@ -11,7 +11,6 @@ class RSpecVersion(dict):
         }
     def __init__(self, version={}):
         
-        self.logger = _SfaLogger('/var/log/sfa.log')
         dict.__init__(self, self.fields)
 
         if not version:
index a3b06ef..12a0e4f 100644 (file)
@@ -1,7 +1,6 @@
 import traceback
 import os.path
 
-from sfa.util.sfalogging import sfa_logger
 from sfa.util.faults import *
 from sfa.util.storage import XmlStorage
 from sfa.util.xrn import get_authority, hrn_to_urn
index bb61bb7..deaf89f 100755 (executable)
@@ -13,7 +13,7 @@ import xmlrpclib
 from mod_python import apache
 
 from sfa.plc.api import SfaAPI
-from sfa.util.sfalogging import sfa_logger
+from sfa.util.sfalogging import logger
 
 api = SfaAPI(interface='aggregate')
 
@@ -53,5 +53,5 @@ def handler(req):
 
     except Exception, err:
         # Log error in /var/log/httpd/(ssl_)?error_log
-        sfa_logger().log_exc('%r'%err)
+        logger.log_exc('%r'%err)
         return apache.HTTP_INTERNAL_SERVER_ERROR
index 0c46084..8879813 100755 (executable)
@@ -13,7 +13,7 @@ import xmlrpclib
 from mod_python import apache
 
 from sfa.plc.api import SfaAPI
-from sfa.util.sfalogging import sfa_logger
+from sfa.util.sfalogging import logger
 
 api = SfaAPI(interface='registry')
 
@@ -53,5 +53,5 @@ def handler(req):
 
     except Exception, err:
         # Log error in /var/log/httpd/(ssl_)?error_log
-        sfa_logger().log_exc('%r'%err)
+        logger.log_exc('%r'%err)
         return apache.HTTP_INTERNAL_SERVER_ERROR
index a28b002..e0f2b92 100755 (executable)
@@ -13,7 +13,7 @@ import xmlrpclib
 from mod_python import apache
 
 from sfa.plc.api import SfaAPI
-from sfa.util.sfalogging import sfa_logger
+from sfa.util.sfalogging import logger
 
 api = SfaAPI(interface='slicemgr')
 
@@ -53,5 +53,5 @@ def handler(req):
 
     except Exception, err:
         # Log error in /var/log/httpd/(ssl_)?error_log
-        sfa_logger().log_exc('%r'%err)
+        logger.log_exc('%r'%err)
         return apache.HTTP_INTERNAL_SERVER_ERROR
index 984b41c..c981158 100755 (executable)
@@ -37,7 +37,7 @@ import traceback
 import sys
 from optparse import OptionParser
 
-from sfa.util.sfalogging import sfa_logger
+from sfa.util.sfalogging import logger
 from sfa.trust.trustedroot import TrustedRootList
 from sfa.trust.certificate import Keypair, Certificate
 from sfa.trust.hierarchy import Hierarchy
@@ -47,6 +47,7 @@ from sfa.plc.api import SfaAPI
 from sfa.server.registry import Registries
 from sfa.server.aggregate import Aggregates
 
+
 # after http://www.erlenstar.demon.co.uk/unix/faq_2.html
 def daemon():
     """Daemonize the current process."""
@@ -83,8 +84,9 @@ def init_server_key(server_key_file, server_cert_file, config, hierarchy):
         if not os.path.exists(key_file):
             # if it doesnt exist then this is probably a fresh interface
             # with no records. Generate a random keypair for now
-            sfa_logger().debug("server's public key not found in %s" % key_file)
-            sfa_logger().debug("generating a random server key pair")
+            logger.debug("server's public key not found in %s" % key_file)
+
+            logger.debug("generating a random server key pair")
             key = Keypair(create=True)
             key.save_to_file(server_key_file)
             init_server_cert(hrn, key, server_cert_file, self_signed=True)    
@@ -113,18 +115,18 @@ def init_server_cert(hrn, key, server_cert_file, self_signed=False):
     else:
         try:
             # look for gid file
-            sfa_logger().debug("generating server cert from gid: %s"% hrn)
+            logger.debug("generating server cert from gid: %s"% hrn)
             hierarchy = Hierarchy()
             auth_info = hierarchy.get_auth_info(hrn)
             gid = GID(filename=auth_info.gid_filename)
             gid.save_to_file(filename=server_cert_file)
         except:
             # fall back to self signed cert
-            sfa_logger().debug("gid for %s not found" % hrn)
+            logger.debug("gid for %s not found" % hrn)
             init_self_signed_cert(hrn, key, server_cert_file)        
         
 def init_self_signed_cert(hrn, key, server_cert_file):
-    sfa_logger().debug("generating self signed cert")
+    logger.debug("generating self signed cert")
     # generate self signed certificate
     cert = Certificate(subject=hrn)
     cert.set_issuer(key=key, subject=hrn)
@@ -187,10 +189,9 @@ def main():
     parser.add_option("-d", "--daemon", dest="daemon", action="store_true",
          help="Run as daemon.", default=False)
     (options, args) = parser.parse_args()
-    sfa_logger().setLevelFromOptVerbose(options.verbose)
 
     config = Config()
-    if config.SFA_API_DEBUG: sfa_logger().setLevelDebug()
+    if config.SFA_API_DEBUG: pass
     hierarchy = Hierarchy()
     server_key_file = os.path.join(hierarchy.basedir, "server.key")
     server_cert_file = os.path.join(hierarchy.basedir, "server.cert")
@@ -227,4 +228,4 @@ if __name__ == "__main__":
     try:
         main()
     except:
-        sfa_logger().log_exc_critical("SFA server is exiting")
+        logger.log_exc_critical("SFA server is exiting")
index 218783e..5466189 100644 (file)
@@ -12,7 +12,7 @@ from sfa.util.config import *
 from sfa.util.xrn import get_authority
 from sfa.util.sfaticket import *
 
-from sfa.util.sfalogging import sfa_logger
+from sfa.util.sfalogging import logger
 
 class Auth:
     """
@@ -36,14 +36,14 @@ class Auth:
         valid = []
         if not isinstance(creds, list):
             creds = [creds]
-        sfa_logger().debug("Auth.checkCredentials with %d creds"%len(creds))
+        logger.debug("Auth.checkCredentials with %d creds"%len(creds))
         for cred in creds:
             try:
                 self.check(cred, operation, hrn)
                 valid.append(cred)
             except:
                 cred_obj=Credential(string=cred)
-                sfa_logger().debug("failed to validate credential - dump=%s"%cred_obj.dump_string(dump_parents=True))
+                logger.debug("failed to validate credential - dump=%s"%cred_obj.dump_string(dump_parents=True))
                 error = sys.exc_info()[:2]
                 continue
             
index 9a2e862..959b763 100644 (file)
@@ -46,9 +46,10 @@ from OpenSSL import crypto
 import M2Crypto
 from M2Crypto import X509
 
-from sfa.util.sfalogging import sfa_logger
+from sfa.util.sfalogging import logger
 from sfa.util.xrn import urn_to_hrn
 from sfa.util.faults import *
+from sfa.util.sfalogging import logger
 
 glo_passphrase_callback = None
 
@@ -111,7 +112,7 @@ def convert_public_key(key):
     try:
         k.load_pubkey_from_file(ssl_fn)
     except:
-        sfa_logger().log_exc("convert_public_key caught exception")
+        logger.log_exc("convert_public_key caught exception")
         k = None
 
     # remove the temporary files
@@ -330,7 +331,6 @@ class Certificate:
         if intermediate:
             self.set_intermediate_ca(intermediate)
 
-    ##
     # Create a blank X509 certificate and store it in this object.
 
     def create(self):
@@ -564,7 +564,7 @@ class Certificate:
     # Sign the certificate using the issuer private key and issuer subject previous set with set_issuer().
 
     def sign(self):
-        sfa_logger().debug('certificate.sign')
+        logger.debug('certificate.sign')
         assert self.cert != None
         assert self.issuerSubject != None
         assert self.issuerKey != None
@@ -649,7 +649,7 @@ class Certificate:
 
         # verify expiration time
         if self.cert.has_expired():
-            sfa_logger().debug("verify_chain: NO our certificate has expired")
+            logger.debug("verify_chain: NO our certificate has expired")
             raise CertExpired(self.get_subject(), "client cert")   
         
         # if this cert is signed by a trusted_cert, then we are set
@@ -657,26 +657,26 @@ class Certificate:
             if self.is_signed_by_cert(trusted_cert):
                 # verify expiration of trusted_cert ?
                 if not trusted_cert.cert.has_expired():
-                    sfa_logger().debug("verify_chain: YES cert %s signed by trusted cert %s"%(
+                    logger.debug("verify_chain: YES cert %s signed by trusted cert %s"%(
                             self.get_subject(), trusted_cert.get_subject()))
                     return trusted_cert
                 else:
-                    sfa_logger().debug("verify_chain: NO cert %s is signed by trusted_cert %s, but this is expired..."%(
+                    logger.debug("verify_chain: NO cert %s is signed by trusted_cert %s, but this is expired..."%(
                             self.get_subject(),trusted_cert.get_subject()))
                     raise CertExpired(self.get_subject(),"trusted_cert %s"%trusted_cert.get_subject())
 
         # if there is no parent, then no way to verify the chain
         if not self.parent:
-            sfa_logger().debug("verify_chain: NO %s has no parent and is not in trusted roots"%self.get_subject())
+            logger.debug("verify_chain: NO %s has no parent and is not in trusted roots"%self.get_subject())
             raise CertMissingParent(self.get_subject())
 
         # if it wasn't signed by the parent...
         if not self.is_signed_by_cert(self.parent):
-            sfa_logger().debug("verify_chain: NO %s is not signed by parent"%self.get_subject())
+            logger.debug("verify_chain: NO %s is not signed by parent"%self.get_subject())
             return CertNotSignedByParent(self.get_subject())
 
         # if the parent isn't verified...
-        sfa_logger().debug("verify_chain: .. %s, -> verifying parent %s"%(self.get_subject(),self.parent.get_subject()))
+        logger.debug("verify_chain: .. %s, -> verifying parent %s"%(self.get_subject(),self.parent.get_subject()))
         self.parent.verify_chain(trusted_certs)
 
         return
@@ -687,7 +687,7 @@ class Certificate:
         triples=[]
         m2x509 = X509.load_cert_string(self.save_to_string())
         nb_extensions=m2x509.get_ext_count()
-        sfa_logger().debug("X509 had %d extensions"%nb_extensions)
+        logger.debug("X509 had %d extensions"%nb_extensions)
         for i in range(nb_extensions):
             ext=m2x509.get_ext_at(i)
             triples.append( (ext.get_name(), ext.get_value(), ext.get_critical(),) )
index 2f38c38..3e1fbcc 100644 (file)
@@ -35,7 +35,7 @@ from xml.dom.minidom import Document, parseString
 from lxml import etree
 
 from sfa.util.faults import *
-from sfa.util.sfalogging import sfa_logger
+from sfa.util.sfalogging import logger
 from sfa.trust.certificate import Keypair
 from sfa.trust.credential_legacy import CredentialLegacy
 from sfa.trust.rights import Right, Rights
@@ -675,7 +675,7 @@ class Credential(object):
                 trusted_cert_objects.append(GID(filename=f))
                 ok_trusted_certs.append(f)
             except Exception, exc:
-                sfa_logger().error("Failed to load trusted cert from %s: %r"%( f, exc))
+                logger.error("Failed to load trusted cert from %s: %r"%( f, exc))
         trusted_certs = ok_trusted_certs
 
         # Use legacy verification if this is a legacy credential
@@ -759,7 +759,7 @@ class Credential(object):
         # Maybe should be (hrn, type) = urn_to_hrn(root_cred_signer.get_urn())
         root_cred_signer_type = root_cred_signer.get_type()
         if (root_cred_signer_type == 'authority'):
-            #sfa_logger().debug('Cred signer is an authority')
+            #logger.debug('Cred signer is an authority')
             # signer is an authority, see if target is in authority's domain
             hrn = root_cred_signer.get_hrn()
             if root_target_gid.get_hrn().startswith(hrn):
index 94240cd..7650d11 100644 (file)
@@ -28,7 +28,7 @@
 import xmlrpclib
 import uuid
 
-from sfa.util.sfalogging import sfa_logger
+from sfa.util.sfalogging import logger 
 from sfa.trust.certificate import Certificate
 from sfa.util.xrn import hrn_to_urn, urn_to_hrn
 
@@ -80,7 +80,7 @@ class GID(Certificate):
         
         Certificate.__init__(self, create, subject, string, filename)
         if subject:
-            sfa_logger().debug("Creating GID for subject: %s" % subject)
+            logger.debug("Creating GID for subject: %s" % subject)
         if uuid:
             self.uuid = int(uuid)
         if hrn:
index 5d7db6f..f28329c 100644 (file)
@@ -15,7 +15,7 @@
 import os
 
 from sfa.util.faults import *
-from sfa.util.sfalogging import sfa_logger
+from sfa.util.sfalogging import logger
 from sfa.util.xrn import get_leaf, get_authority, hrn_to_urn, urn_to_hrn
 from sfa.trust.certificate import Keypair
 from sfa.trust.credential import Credential
@@ -33,7 +33,6 @@ class AuthInfo:
     gid_filename = None
     privkey_filename = None
     dbinfo_filename = None
-
     ##
     # Initialize and authority object.
     #
@@ -159,7 +158,7 @@ class Hierarchy:
 
     def create_auth(self, xrn, create_parents=False):
         hrn, type = urn_to_hrn(xrn)
-        sfa_logger().debug("Hierarchy: creating authority: %s"% hrn)
+        logger.debug("Hierarchy: creating authority: %s"% hrn)
 
         # create the parent authority if necessary
         parent_hrn = get_authority(hrn)
@@ -179,7 +178,7 @@ class Hierarchy:
                 pass
 
         if os.path.exists(privkey_filename):
-            sfa_logger().debug("using existing key %r for authority %r"%(privkey_filename,hrn))
+            logger.debug("using existing key %r for authority %r"%(privkey_filename,hrn))
             pkey = Keypair(filename = privkey_filename)
         else:
             pkey = Keypair(create = True)
@@ -205,7 +204,7 @@ class Hierarchy:
     def get_auth_info(self, xrn):
         hrn, type = urn_to_hrn(xrn)
         if not self.auth_exists(hrn):
-            sfa_logger().warning("Hierarchy: mising authority - xrn=%s, hrn=%s"%(xrn,hrn))
+            logger.warning("Hierarchy: mising authority - xrn=%s, hrn=%s"%(xrn,hrn))
             raise MissingAuthority(hrn)
 
         (directory, gid_filename, privkey_filename, dbinfo_filename) = \
index 39cde57..19cd4d0 100644 (file)
@@ -22,7 +22,7 @@ try: import pgdb
 except: print >> sys.stderr, "WARNING, could not import pgdb"
 
 from sfa.util.faults import *
-from sfa.util.sfalogging import sfa_logger
+from sfa.util.sfalogging import logger
 
 if not psycopg2:
     is8bit = re.compile("[\x80-\xff]").search
@@ -183,21 +183,21 @@ class PostgreSQL:
 
             if not params:
                 if self.debug:
-                    sfa_logger().debug('execute0 %r'%query)
+                    logger.debug('execute0 %r'%query)
                 cursor.execute(query)
             elif isinstance(params,dict):
                 if self.debug:
-                    sfa_logger().debug('execute-dict: params=[%r] query=[%r]'%(params,query%params))
+                    logger.debug('execute-dict: params=[%r] query=[%r]'%(params,query%params))
                 cursor.execute(query,params)
             elif isinstance(params,tuple) and len(params)==1:
                 if self.debug:
-                    sfa_logger().debug('execute-tuple %r'%(query%params[0]))
+                    logger.debug('execute-tuple %r'%(query%params[0]))
                 cursor.execute(query,params[0])
             else:
                 param_seq=(params,)
                 if self.debug:
                     for params in param_seq:
-                        sfa_logger().debug('executemany %r'%(query%params))
+                        logger.debug('executemany %r'%(query%params))
                 cursor.executemany(query, param_seq)
             (self.rowcount, self.description, self.lastrowid) = \
                             (cursor.rowcount, cursor.description, cursor.lastrowid)
@@ -207,11 +207,11 @@ class PostgreSQL:
             except:
                 pass
             uuid = commands.getoutput("uuidgen")
-            sfa_logger().error("Database error %s:" % uuid)
-            sfa_logger().error("Exception=%r"%e)
-            sfa_logger().error("Query=%r"%query)
-            sfa_logger().error("Params=%r"%pformat(params))
-            sfa_logger().log_exc("PostgreSQL.execute caught exception")
+            logger.error("Database error %s:" % uuid)
+            logger.error("Exception=%r"%e)
+            logger.error("Query=%r"%query)
+            logger.error("Params=%r"%pformat(params))
+            logger.log_exc("PostgreSQL.execute caught exception")
             raise SfaDBError("Please contact support: %s" % str(e))
 
         return cursor
index f9aed1c..67d155e 100644 (file)
@@ -8,7 +8,7 @@ import traceback
 import string
 import xmlrpclib
 
-from sfa.util.sfalogging import sfa_logger
+from sfa.util.sfalogging import logger
 from sfa.trust.auth import Auth
 from sfa.util.config import *
 from sfa.util.faults import *
@@ -143,8 +143,8 @@ class BaseAPI:
         self.credential = None
         self.source = None 
         self.time_format = "%Y-%m-%d %H:%M:%S"
-        self.logger=sfa_logger
-        
+        self.logger = logger
         # load registries
         from sfa.server.registry import Registries
         self.registries = Registries(self) 
@@ -238,7 +238,7 @@ class BaseAPI:
         except SfaFault, fault:
             result = fault 
         except Exception, fault:
-            sfa_logger().log_exc("BaseAPI.handle has caught Exception")
+            logger.log_exc("BaseAPI.handle has caught Exception")
             result = SfaAPIError(fault)
 
 
index 904c42b..ead60bb 100644 (file)
@@ -3,7 +3,7 @@
 import threading
 import time
 
-from sfa.util.sfalogging import sfa_logger
+from sfa.util.sfalogging import logger
 
 """
 Callids: a simple mechanism to remember the call ids served so fas
@@ -33,15 +33,15 @@ class _call_ids_impl (dict):
         if not call_id: return False
         has_lock=False
         for attempt in range(_call_ids_impl.retries):
-            if debug: sfa_logger().debug("Waiting for lock (%d)"%attempt)
+            if debug: logger.debug("Waiting for lock (%d)"%attempt)
             if self._lock.acquire(False): 
                 has_lock=True
-                if debug: sfa_logger().debug("got lock (%d)"%attempt)
+                if debug: logger.debug("got lock (%d)"%attempt)
                 break
             time.sleep(float(_call_ids_impl.wait_ms)/1000)
         # in the unlikely event where we can't get the lock
         if not has_lock:
-            sfa_logger().warning("_call_ids_impl.should_handle_call_id: could not acquire lock")
+            logger.warning("_call_ids_impl.should_handle_call_id: could not acquire lock")
             return False
         # we're good to go
         if self.has_key(call_id):
@@ -51,7 +51,7 @@ class _call_ids_impl (dict):
         self[call_id]=time.time()
         self._purge()
         self._lock.release()
-        if debug: sfa_logger().debug("released lock")
+        if debug: logger.debug("released lock")
         return False
         
     def _purge(self):
@@ -60,11 +60,11 @@ class _call_ids_impl (dict):
         for (k,v) in self.iteritems():
             if (now-v) >= _call_ids_impl.purge_timeout: o_keys.append(k)
         for k in o_keys: 
-            if debug: sfa_logger().debug("Purging call_id %r (%s)"%(k,time.strftime("%H:%M:%S",time.localtime(self[k]))))
+            if debug: logger.debug("Purging call_id %r (%s)"%(k,time.strftime("%H:%M:%S",time.localtime(self[k]))))
             del self[k]
         if debug:
-            sfa_logger().debug("AFTER PURGE")
-            for (k,v) in self.iteritems(): sfa_logger().debug("%s -> %s"%(k,time.strftime("%H:%M:%S",time.localtime(v))))
+            logger.debug("AFTER PURGE")
+            for (k,v) in self.iteritems(): logger.debug("%s -> %s"%(k,time.strftime("%H:%M:%S",time.localtime(v))))
         
 def Callids ():
     if not _call_ids_impl._instance:
index c12104b..9fa40f9 100644 (file)
@@ -19,7 +19,7 @@ import SimpleHTTPServer
 import SimpleXMLRPCServer
 from OpenSSL import SSL
 
-from sfa.util.sfalogging import sfa_logger
+from sfa.util.sfalogging import logger
 from sfa.trust.certificate import Keypair, Certificate
 from sfa.trust.credential import *
 from sfa.util.faults import *
@@ -74,7 +74,7 @@ class SecureXMLRpcRequestHandler(SimpleXMLRPCServer.SimpleXMLRPCRequestHandler):
             # internal error, report as HTTP server error
             self.send_response(500)
             self.end_headers()
-            sfa_logger().log_exc("componentserver.SecureXMLRpcRequestHandler.do_POST")
+            logger.log_exc("componentserver.SecureXMLRpcRequestHandler.do_POST")
         else:
             # got a valid XML RPC response
             self.send_response(200)
index 43b589c..4c37c67 100644 (file)
@@ -11,7 +11,7 @@ import textwrap
 import xmlrpclib
 
 
-from sfa.util.sfalogging import sfa_logger
+from sfa.util.sfalogging import logger
 from sfa.util.faults import * 
 from sfa.util.parameter import Parameter, Mixed, python_type, xmlrpc_type
 from sfa.trust.auth import Auth
@@ -80,12 +80,12 @@ class Method:
                 self.type_check(name, value, expected, args)
 
             if self.api.config.SFA_API_DEBUG:
-                sfa_logger().debug("method.__call__ [%s] : BEG %s"%(self.api.interface,methodname))
+                logger.debug("method.__call__ [%s] : BEG %s"%(self.api.interface,methodname))
             result = self.call(*args, **kwds)
 
             runtime = time.time() - start
             if self.api.config.SFA_API_DEBUG or hasattr(self, 'message'):
-                sfa_logger().debug("method.__call__ [%s] : END %s in %02f s (%s)"%\
+                logger.debug("method.__call__ [%s] : END %s in %02f s (%s)"%\
                                        (self.api.interface,methodname,runtime,getattr(self,'message',"[no-msg]")))
 
             return result
@@ -97,7 +97,7 @@ class Method:
             # Prepend caller and method name to expected faults
             fault.faultString = caller + ": " +  self.name + ": " + fault.faultString
             runtime = time.time() - start
-            sfa_logger().log_exc("Method %s raised an exception"%self.name) 
+            logger.log_exc("Method %s raised an exception"%self.name) 
             raise fault
 
 
index ffc816c..572d660 100644 (file)
@@ -7,7 +7,7 @@ import httplib
 from xml.dom import minidom
 from lxml import etree
 
-from sfa.util.sfalogging import sfa_logger
+from sfa.util.sfalogging import info_logger
 
 class RSpec:
 
@@ -232,11 +232,11 @@ class RSpec:
             except Exception, e:
                 # logging.debug("%s: web file not found" % xsdURI)
                 # logging.debug("Using local file %s" % self.xsd")
-                sfa_logger().log_exc("rspec.parseXSD: can't find %s on the web. Continuing." % xsdURI)
+                info_logger.log_exc("rspec.parseXSD: can't find %s on the web. Continuing." % xsdURI)
         if not schemaDom:
             if os.path.exists(xsdURI):
                 # logging.debug("using local copy.")
-                sfa_logger().debug("rspec.parseXSD: Using local %s" % xsdURI)
+                info_logger.debug("rspec.parseXSD: Using local %s" % xsdURI)
                 schemaDom = minidom.parse(xsdURI)
             else:
                 raise Exception("rspec.parseXSD: can't find xsd locally")
index 1ccc984..89f15af 100755 (executable)
@@ -8,7 +8,7 @@ from StringIO import StringIO
 from optparse import OptionParser
 
 from sfa.util.faults import *
-from sfa.util.sfalogging import sfa_logger
+from sfa.util.sfalogging import logger
 
 def merge_rspecs(rspecs):
     """
@@ -24,13 +24,13 @@ def merge_rspecs(rspecs):
         try:
             known_networks[network.get('name')]=True
         except:
-            sfa_logger().error("merge_rspecs: cannot register network with no name in rspec")
+            logger.error("merge_rspecs: cannot register network with no name in rspec")
             pass
     def is_registered_network (network):
         try:
             return network.get('name') in known_networks
         except:
-            sfa_logger().error("merge_rspecs: cannot retrieve network with no name in rspec")
+            logger.error("merge_rspecs: cannot retrieve network with no name in rspec")
             return False
 
     # the resulting tree
@@ -42,13 +42,13 @@ def merge_rspecs(rspecs):
             tree = etree.parse(StringIO(input_rspec))
         except etree.XMLSyntaxError:
             # consider failing silently here
-            sfa_logger().log_exc("merge_rspecs, parse error")
+            logger.log_exc("merge_rspecs, parse error")
             message = str(sys.exc_info()[1]) + ' with ' + input_rspec
             raise InvalidRSpec(message)
 
         root = tree.getroot()
         if not root.get("type") in ["SFA"]:
-            sfa_logger().error("merge_rspecs: unexpected type for rspec root, %s"%root.get('type'))
+            logger.error("merge_rspecs: unexpected type for rspec root, %s"%root.get('type'))
             continue
         if rspec == None:
             # we scan the first input, register all networks
index b4fd2ff..fadd4ca 100644 (file)
@@ -24,7 +24,7 @@ from sfa.trust.credential import *
 from sfa.util.faults import *
 from sfa.plc.api import SfaAPI
 from sfa.util.cache import Cache 
-from sfa.util.sfalogging import sfa_logger
+from sfa.util.sfalogging import logger
 
 ##
 # Verification callback for pyOpenSSL. We do our own checking of keys because
@@ -110,7 +110,7 @@ class SecureXMLRpcRequestHandler(SimpleXMLRPCServer.SimpleXMLRPCRequestHandler):
         except Exception, fault:
             # This should only happen if the module is buggy
             # internal error, report as HTTP server error
-            sfa_logger().log_exc("server.do_POST")
+            logger.log_exc("server.do_POST")
             response = self.api.prepare_response(fault)
             #self.send_response(500)
             #self.end_headers()
@@ -134,7 +134,7 @@ class SecureXMLRPCServer(BaseHTTPServer.HTTPServer,SimpleXMLRPCServer.SimpleXMLR
 
         It it very similar to SimpleXMLRPCServer but it uses HTTPS for transporting XML data.
         """
-        sfa_logger().debug("SecureXMLRPCServer.__init__, server_address=%s, cert_file=%s"%(server_address,cert_file))
+        logger.debug("SecureXMLRPCServer.__init__, server_address=%s, cert_file=%s"%(server_address,cert_file))
         self.logRequests = logRequests
         self.interface = None
         self.key_file = key_file
@@ -171,7 +171,7 @@ class SecureXMLRPCServer(BaseHTTPServer.HTTPServer,SimpleXMLRPCServer.SimpleXMLR
     # the client.
 
     def _dispatch(self, method, params):
-        sfa_logger().debug("SecureXMLRPCServer._dispatch, method=%s"%method)
+        logger.debug("SecureXMLRPCServer._dispatch, method=%s"%method)
         try:
             return SimpleXMLRPCServer.SimpleXMLRPCDispatcher._dispatch(self, method, params)
         except:
@@ -287,7 +287,7 @@ class SfaServer(threading.Thread):
         self.server.interface=interface
         self.trusted_cert_list = None
         self.register_functions()
-        sfa_logger().info("Starting SfaServer, interface=%s"%interface)
+        logger.info("Starting SfaServer, interface=%s"%interface)
 
     ##
     # Register functions that will be served by the XMLRPC server. This
index b4a1290..f812517 100755 (executable)
@@ -15,21 +15,21 @@ class _SfaLogger:
     def __init__ (self,logfile=None,loggername=None,level=logging.INFO):
         # default is to locate loggername from the logfile if avail.
         if not logfile:
-            loggername='console'
-            handler=logging.StreamHandler()
-            handler.setFormatter(logging.Formatter("%(levelname)s %(message)s"))
-        else:
-            if not loggername:
-                loggername=os.path.basename(logfile)
-            try:
-                handler=logging.handlers.RotatingFileHandler(logfile,maxBytes=1000000, backupCount=5) 
-            except IOError:
-                # This is usually a permissions error becaue the file is
-                # owned by root, but httpd is trying to access it.
-                tmplogfile=os.getenv("TMPDIR", "/tmp") + os.path.sep + os.path.basename(logfile)
-                handler=logging.handlers.RotatingFileHandler(tmplogfile,maxBytes=1000000, backupCount=5) 
-            handler.setFormatter(logging.Formatter("%(asctime)s - %(levelname)s - %(message)s"))
-
+            #loggername='console'
+            #handler=logging.StreamHandler()
+            #handler.setFormatter(logging.Formatter("%(levelname)s %(message)s"))
+            logfile = "/var/log/sfa.log"
+
+        if not loggername:
+            loggername=os.path.basename(logfile)
+        try:
+            handler=logging.handlers.RotatingFileHandler(logfile,maxBytes=1000000, backupCount=5) 
+        except IOError:
+            # This is usually a permissions error becaue the file is
+            # owned by root, but httpd is trying to access it.
+            tmplogfile=os.getenv("TMPDIR", "/tmp") + os.path.sep + os.path.basename(logfile)
+            handler=logging.handlers.RotatingFileHandler(tmplogfile,maxBytes=1000000, backupCount=5) 
+        handler.setFormatter(logging.Formatter("%(asctime)s - %(levelname)s - %(message)s"))
         self.logger=logging.getLogger(loggername)
         self.logger.setLevel(level)
         self.logger.addHandler(handler)
@@ -84,30 +84,13 @@ class _SfaLogger:
         self.debug("%s BEG STACK"%message+"\n"+to_log)
         self.debug("%s END STACK"%message)
 
-####################
-# import-related operations go in this file
-_import_logger=_SfaLogger(logfile='/var/log/sfa_import.log')
-# servers log into /var/log/sfa.log
-_server_logger=_SfaLogger(logfile='/var/log/sfa.log')
-## clients use the console
-#_console_logger=_SfaLogger()
-
-# default is to use the server-side logger
-#_the_logger=_server_logger
-
-# clients would change the default by issuing one of these call
-#def sfa_logger_goes_to_console():
-#    current_module=sys.modules[globals()['__name__']]
-#    current_module._the_logger=_console_logger
-#
-# clients would change the default by issuing one of these call
-#def sfa_logger_goes_to_import():
-#    current_module=sys.modules[globals()['__name__']]
-#    current_module._the_logger=_import_logger
-
-# this is how to retrieve the 'right' logger
-def sfa_logger():
-    return _server_logger
+
+info_logger = _SfaLogger(loggername='info', level=logging.INFO)
+debug_logger = _SfaLogger(loggername='debug', level=logging.DEBUG)
+warn_logger = _SfaLogger(loggername='warning', level=logging.WARNING)
+error_logger = _SfaLogger(loggername='error', level=logging.ERROR)
+critical_logger = _SfaLogger(loggername='critical', level=logging.CRITICAL)
+logger = info_logger
 
 ########################################
 import time
@@ -145,9 +128,6 @@ if __name__ == '__main__':
     logger.setLevel(logging.DEBUG)
     logger.debug("logger.debug again")
     
-    #sfa_logger_goes_to_console()
-    my_logger=sfa_logger()
-    my_logger.info("redirected to console")
 
     @profile(my_logger)
     def sleep(seconds = 1):
index 61e16fe..b5e9c01 100644 (file)
@@ -3,8 +3,7 @@
 import httplib
 import xmlrpclib
 
-from sfa.util.sfalogging import sfa_logger
-
+from sfa.util.sfalogging import logger
 ##
 # ServerException, ExceptionUnmarshaller
 #
@@ -58,11 +57,10 @@ class XMLRPCServerProxy(xmlrpclib.ServerProxy):
         verbose = False
         if options and options.debug:
             verbose = True
-#        sfa_logger().debug ("xmlrpcprotocol.XMLRPCServerProxy.__init__ %s (with verbose=%s)"%(url,verbose))
         xmlrpclib.ServerProxy.__init__(self, url, transport, allow_none=allow_none, verbose=verbose)
 
     def __getattr__(self, attr):
-        sfa_logger().debug ("xml-rpc %s method:%s"%(self.url,attr))
+        logger.debug ("xml-rpc %s method:%s"%(self.url,attr))
         return xmlrpclib.ServerProxy.__getattr__(self, attr)
 
 
index d5ad2d4..752e7a9 100644 (file)
@@ -1,7 +1,6 @@
 import re
 
 from sfa.util.faults import *
-from sfa.util.sfalogging import sfa_logger
 
 # for convenience and smoother translation - we should get rid of these functions eventually 
 def get_leaf(hrn): return Xrn(hrn).get_leaf()
@@ -74,7 +73,7 @@ class Xrn:
             self.hrn_to_urn()
 # happens all the time ..
 #        if not type:
-#            sfa_logger().debug("type-less Xrn's are not safe")
+#            debug_logger.debug("type-less Xrn's are not safe")
 
     def get_urn(self): return self.urn
     def get_hrn(self): return self.hrn