summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/saml2/__init__.py3
-rw-r--r--src/saml2/config.py69
-rw-r--r--src/saml2/entity.py1
-rw-r--r--tests/test_31_config.py49
4 files changed, 9 insertions, 113 deletions
diff --git a/src/saml2/__init__.py b/src/saml2/__init__.py
index ab0f1bf5..5fa769f9 100644
--- a/src/saml2/__init__.py
+++ b/src/saml2/__init__.py
@@ -40,8 +40,7 @@ except ImportError:
import defusedxml.ElementTree
-root_logger = logging.getLogger(__name__)
-root_logger.level = logging.NOTSET
+logger = logging.getLogger(__name__)
NAMESPACE = 'urn:oasis:names:tc:SAML:2.0:assertion'
# TEMPLATE = '{urn:oasis:names:tc:SAML:2.0:assertion}%s'
diff --git a/src/saml2/config.py b/src/saml2/config.py
index 274e3960..1bd2827a 100644
--- a/src/saml2/config.py
+++ b/src/saml2/config.py
@@ -10,11 +10,12 @@ import sys
import six
-from saml2 import root_logger, BINDING_URI, SAMLError
-from saml2 import BINDING_SOAP
-from saml2 import BINDING_HTTP_REDIRECT
-from saml2 import BINDING_HTTP_POST
from saml2 import BINDING_HTTP_ARTIFACT
+from saml2 import BINDING_HTTP_POST
+from saml2 import BINDING_HTTP_REDIRECT
+from saml2 import BINDING_SOAP
+from saml2 import BINDING_URI
+from saml2 import SAMLError
from saml2.attribute_converter import ac_factory
from saml2.assertion import Policy
@@ -22,6 +23,7 @@ from saml2.mdstore import MetadataStore
from saml2.saml import NAME_FORMAT_URI
from saml2.virtual_org import VirtualOrg
+
logger = logging.getLogger(__name__)
__author__ = 'rolandh'
@@ -47,7 +49,6 @@ COMMON_ARGS = [
"contact_person",
"name_form",
"virtual_organization",
- "logger",
"only_use_keys_in_metadata",
"disable_ssl_certificate_validation",
"preferred_binding",
@@ -211,7 +212,6 @@ class Config(object):
self.name_id_format = None
self.name_id_format_allow_create = None
self.virtual_organization = None
- self.logger = None
self.only_use_keys_in_metadata = True
self.logout_requests_signed = None
self.disable_ssl_certificate_validation = None
@@ -453,63 +453,6 @@ class Config(object):
else:
return unspec
- def log_handler(self):
- try:
- _logconf = self.logger
- except KeyError:
- return None
-
- handler = None
- for htyp in LOG_HANDLER:
- if htyp in _logconf:
- if htyp == "syslog":
- args = _logconf[htyp]
- if "socktype" in args:
- import socket
- if args["socktype"] == "dgram":
- args["socktype"] = socket.SOCK_DGRAM
- elif args["socktype"] == "stream":
- args["socktype"] = socket.SOCK_STREAM
- else:
- raise ConfigurationError("Unknown socktype!")
- try:
- handler = LOG_HANDLER[htyp](**args)
- except TypeError: # difference between 2.6 and 2.7
- del args["socktype"]
- handler = LOG_HANDLER[htyp](**args)
- else:
- handler = LOG_HANDLER[htyp](**_logconf[htyp])
- break
-
- if handler is None:
- # default if rotating logger
- handler = LOG_HANDLER["rotating"]()
-
- if "format" in _logconf:
- formatter = logging.Formatter(_logconf["format"])
- else:
- formatter = logging.Formatter(LOG_FORMAT)
-
- handler.setFormatter(formatter)
- return handler
-
- def setup_logger(self):
- if root_logger.level != logging.NOTSET: # Someone got there before me
- return root_logger
-
- _logconf = self.logger
- if _logconf is None:
- return root_logger
-
- try:
- root_logger.setLevel(LOG_LEVEL[_logconf["loglevel"].lower()])
- except KeyError: # reasonable default
- root_logger.setLevel(logging.INFO)
-
- root_logger.addHandler(self.log_handler())
- root_logger.info("Logging started")
- return root_logger
-
def endpoint2service(self, endpoint, context=None):
endps = self.getattr("endpoints", context)
diff --git a/src/saml2/entity.py b/src/saml2/entity.py
index 2ab1995b..b7fe5c30 100644
--- a/src/saml2/entity.py
+++ b/src/saml2/entity.py
@@ -159,7 +159,6 @@ class Entity(HTTPBase):
vo.sp = self
self.metadata = self.config.metadata
- self.config.setup_logger()
self.debug = self.config.debug
self.sec = security_context(self.config)
diff --git a/tests/test_31_config.py b/tests/test_31_config.py
index 407e46e2..bb19d85c 100644
--- a/tests/test_31_config.py
+++ b/tests/test_31_config.py
@@ -8,7 +8,7 @@ from saml2.mdstore import MetadataStore, name
from saml2 import BINDING_HTTP_REDIRECT, BINDING_SOAP, BINDING_HTTP_POST
from saml2.config import SPConfig, IdPConfig, Config
-from saml2 import root_logger
+from saml2 import logger
from pathutils import dotname, full_path
from saml2.sigver import security_context, CryptoBackendXMLSecurity
@@ -297,57 +297,12 @@ def test_wayf():
assert name(ent) == 'Example Co.'
assert name(ent, "se") == 'Exempel AB'
- c.setup_logger()
-
- assert root_logger.level != logging.NOTSET
- assert root_logger.level == logging.INFO
- assert len(root_logger.handlers) == 1
- assert isinstance(root_logger.handlers[0],
- logging.handlers.RotatingFileHandler)
- handler = root_logger.handlers[0]
- assert handler.backupCount == 5
- try:
- assert handler.maxBytes == 100000
- except AssertionError:
- assert handler.maxBytes == 500000
- assert handler.mode == "a"
- assert root_logger.name == "saml2"
- assert root_logger.level == 20
-
def test_conf_syslog():
c = SPConfig().load_file("server_conf_syslog")
c.context = "sp"
- # otherwise the logger setting is not changed
- root_logger.level = logging.NOTSET
- while root_logger.handlers:
- handler = root_logger.handlers[-1]
- root_logger.removeHandler(handler)
- handler.flush()
- handler.close()
-
- print(c.logger)
- c.setup_logger()
-
- assert root_logger.level != logging.NOTSET
- assert root_logger.level == logging.INFO
- assert len(root_logger.handlers) == 1
- assert isinstance(root_logger.handlers[0],
- logging.handlers.SysLogHandler)
- handler = root_logger.handlers[0]
- print(handler.__dict__)
- assert handler.facility == "local3"
- assert handler.address == ('localhost', 514)
- if ((sys.version_info.major == 2 and sys.version_info.minor >= 7) or
- sys.version_info.major > 2):
- assert handler.socktype == 2
- else:
- pass
- assert root_logger.name == "saml2"
- assert root_logger.level == 20
-
-#noinspection PyUnresolvedReferences
+
def test_3():
cnf = Config()
cnf.load_file(dotname("sp_1_conf"))