From 1c494e1843d857dbc63e46274c205293129b96d3 Mon Sep 17 00:00:00 2001 From: Tony Mack Date: Mon, 20 Jun 2011 13:04:31 -0400 Subject: [PATCH] stop redundant logging --- sfa/client/sfadump.py | 3 +-- sfa/client/sfascan.py | 3 +-- sfa/rspecs/pg_rspec.py | 2 +- sfa/util/sfalogging.py | 57 ++++++++++++++++++++---------------------- 4 files changed, 30 insertions(+), 35 deletions(-) diff --git a/sfa/client/sfadump.py b/sfa/client/sfadump.py index b1169b90..1ea1a7c0 100755 --- a/sfa/client/sfadump.py +++ b/sfa/client/sfadump.py @@ -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, sfa_logger_goes_to_console +from sfa.util.sfalogging import sfa_logger def determine_sfa_filekind(fn): @@ -100,7 +100,6 @@ def handle_input_kind (filename, options, kind): print "%s: unknown filekind '%s'"% (filename,kind) def main(): - sfa_logger_goes_to_console() usage = """%prog file1 [ .. filen] display info on input files""" parser = OptionParser(usage=usage) diff --git a/sfa/client/sfascan.py b/sfa/client/sfascan.py index f85384dc..eff17ec0 100755 --- a/sfa/client/sfascan.py +++ b/sfa/client/sfascan.py @@ -10,7 +10,7 @@ import pygraphviz from optparse import OptionParser from sfa.client.sfi import Sfi -from sfa.util.sfalogging import sfa_logger,sfa_logger_goes_to_console +from sfa.util.sfalogging import sfa_logger import sfa.util.xmlrpcprotocol as xmlrpcprotocol def url_hostname_port (url): @@ -201,7 +201,6 @@ class SfaScan: default_outfiles=['sfa.png','sfa.svg','sfa.dot'] def main(): - sfa_logger_goes_to_console() usage="%prog [options] url-entry-point(s)" parser=OptionParser(usage=usage) parser.add_option("-o","--output",action='append',dest='outfiles',default=[], diff --git a/sfa/rspecs/pg_rspec.py b/sfa/rspecs/pg_rspec.py index 3d2ae4f0..7c3f7601 100755 --- a/sfa/rspecs/pg_rspec.py +++ b/sfa/rspecs/pg_rspec.py @@ -32,7 +32,7 @@ pg_rspec_request_version = RSpecVersion(_request_version) class PGRSpec(RSpec): xml = None header = '\n' - template = """""" + template = '' def __init__(self, rspec="", namespaces={}, type=None): if not type: diff --git a/sfa/util/sfalogging.py b/sfa/util/sfalogging.py index 42e2e678..b4a12905 100755 --- a/sfa/util/sfalogging.py +++ b/sfa/util/sfalogging.py @@ -54,24 +54,21 @@ class _SfaLogger: self.logger.setLevel(logging.DEBUG) #################### - def wrap(fun): - def wrapped(self,msg,*args,**kwds): - native=getattr(self.logger,fun.__name__) - return native(msg,*args,**kwds) - #wrapped.__doc__=native.__doc__ - return wrapped - - @wrap - def critical(): pass - @wrap - def error(): pass - @wrap - def warning(): pass - @wrap - def info(): pass - @wrap - def debug(): pass - + def info(self, msg): + self.logger.info(msg) + + def debug(self, msg): + self.logger.debug(msg) + + def warn(self, msg): + self.logger.warn(msg) + + def error(self, msg): + self.logger.error(msg) + + def critical(self, msg): + self.logger.critical(msg) + # logs an exception - use in an except statement def log_exc(self,message): self.error("%s BEG TRACEBACK"%message+"\n"+traceback.format_exc().strip("\n")) @@ -92,25 +89,25 @@ class _SfaLogger: _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() +## clients use the console +#_console_logger=_SfaLogger() # default is to use the server-side logger -_the_logger=_server_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 - +#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 +#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 _the_logger + return _server_logger ######################################## import time @@ -148,7 +145,7 @@ if __name__ == '__main__': logger.setLevel(logging.DEBUG) logger.debug("logger.debug again") - sfa_logger_goes_to_console() + #sfa_logger_goes_to_console() my_logger=sfa_logger() my_logger.info("redirected to console") -- 2.43.0