diff --git a/example/idp/idp.py b/example/idp/idp.py index 9189670..08f62d0 100755 --- a/example/idp/idp.py +++ b/example/idp/idp.py @@ -253,22 +253,13 @@ def application(environ, start_response): from repoze.who.config import make_middleware_with_config APP_WITH_AUTH = make_middleware_with_config(application, {"here":"."}, - './who.ini', log_file="app.log") + './who.ini', log_file="repoze_who.log") # ---------------------------------------------------------------------------- if __name__ == '__main__': import sys from wsgiref.simple_server import make_server - import logging - from saml2.config import LOG_FORMAT, LOG_HANDLER - - handler = LOG_HANDLER["rotating"]("./idp.log") - formatter = logging.Formatter(LOG_FORMAT) - handler.setFormatter(formatter) - root_logger.addHandler(handler) - root_logger.info("Logging started") - root_logger.setLevel(logging.INFO) PORT = 8088 diff --git a/example/idp/idp_conf.py b/example/idp/idp_conf.py index 872bf1c..045c6e5 100644 --- a/example/idp/idp_conf.py +++ b/example/idp/idp_conf.py @@ -42,4 +42,12 @@ CONFIG={ # the identifier returned to a SP #"xmlsec_binary": "/usr/local/bin/xmlsec1", "attribute_map_dir" : "./attributemaps", + "logger": { + "rotating": { + "filename": "idp.log", + "maxBytes": 100000, + "backupCount": 5, + }, + "loglevel": "debug", + } } diff --git a/example/sp/sp.py b/example/sp/sp.py index a626188..95bc523 100755 --- a/example/sp/sp.py +++ b/example/sp/sp.py @@ -1,4 +1,5 @@ #!/usr/bin/env python +import logging import re from cgi import parse_qs @@ -157,8 +158,9 @@ def application(environ, start_response): path = environ.get('PATH_INFO', '').lstrip('/') logger = environ.get('repoze.who.logger') - if logger: - logger.info( " PATH: %s" % path) + logger.info(" PATH: %s" % path) + logger.info("logger name: %s" % logger.name) + logger.info(logging.Logger.manager.loggerDict) for regex, callback in urls: if user: match = re.search(regex, path) @@ -177,7 +179,7 @@ def application(environ, start_response): from repoze.who.config import make_middleware_with_config app_with_auth = make_middleware_with_config(application, {"here":"."}, - './who.ini', log_file="sp.log") + './who.ini', log_file="repoze_who.log") # ---------------------------------------------------------------------------- PORT = 8087 diff --git a/example/sp/sp_conf.py b/example/sp/sp_conf.py index 69cf555..faebdf8 100644 --- a/example/sp/sp_conf.py +++ b/example/sp/sp_conf.py @@ -41,5 +41,13 @@ CONFIG = { }, ], #"xmlsec_binary":"/usr/local/bin/xmlsec1", - "name_form": NAME_FORMAT_URI + "name_form": NAME_FORMAT_URI, + "logger": { + "rotating": { + "filename": "sp.log", + "maxBytes": 100000, + "backupCount": 5, + }, + "loglevel": "debug", + } } diff --git a/src/s2repoze/plugins/sp.py b/src/s2repoze/plugins/sp.py index d5ba984..e7b0eac 100644 --- a/src/s2repoze/plugins/sp.py +++ b/src/s2repoze/plugins/sp.py @@ -47,7 +47,7 @@ from saml2.profile import paos #from saml2.population import Population #from saml2.attribute_resolver import AttributeResolver -logger = logging.getLogger(__name__) +logger = logging.getLogger("repoze.who.sp") PAOS_HEADER_INFO = 'ver="%s";"%s"' % (paos.NAMESPACE, ecp.SERVICE) @@ -149,7 +149,7 @@ class SAML2Plugin(FormPluginBase): post_env = environ.copy() post_env['QUERY_STRING'] = '' - _ = get_body(environ, logger) + _ = get_body(environ) try: post = cgi.FieldStorage( @@ -511,7 +511,6 @@ def make_plugin(rememberer_name=None, # plugin for remember sid_store="", identity_cache="", discovery="", - debug=0 ): if saml_conf is "": diff --git a/src/saml2/__init__.py b/src/saml2/__init__.py index b95d22a..b85672e 100644 --- a/src/saml2/__init__.py +++ b/src/saml2/__init__.py @@ -63,7 +63,7 @@ except ImportError: except ImportError: from elementtree import ElementTree -root_logger = logging.getLogger("pySAML2") +root_logger = logging.getLogger(__name__) root_logger.level = logging.NOTSET NAMESPACE = 'urn:oasis:names:tc:SAML:2.0:assertion' diff --git a/src/saml2/client.py b/src/saml2/client.py index 1ec5c9c..9a97d5c 100644 --- a/src/saml2/client.py +++ b/src/saml2/client.py @@ -111,7 +111,8 @@ class Saml2Client(object): raise Exception("Missing configuration") self.metadata = self.config.metadata - + self.config.setup_logger() + # we copy the config.debug variable in an internal # field for convenience and because we may need to # change it during the tests diff --git a/src/saml2/config.py b/src/saml2/config.py index 373db57..65650cb 100644 --- a/src/saml2/config.py +++ b/src/saml2/config.py @@ -314,13 +314,15 @@ class Config(object): if root_logger.level != logging.NOTSET: # Someone got there before me return root_logger - if _logconf is None: - return None + try: + _logconf = self._attr[""]["logger"] + except KeyError: + return root_logger try: root_logger.setLevel(LOG_LEVEL[_logconf["loglevel"].lower()]) except KeyError: # reasonable default - root_logger.setLevel(logging.WARNING) + root_logger.setLevel(logging.INFO) root_logger.addHandler(self.log_handler()) root_logger.info("Logging started") diff --git a/tests/server_conf.py b/tests/server_conf.py index d7b6505..4c6802b 100644 --- a/tests/server_conf.py +++ b/tests/server_conf.py @@ -53,6 +53,6 @@ CONFIG={ "maxBytes": 100000, "backupCount": 5, }, - "loglevel": "warning", + "loglevel": "info", } }