Skip to content

Commit 832d26f

Browse files
committed
Remove logger configuration
``` ************* Module saml2.config src/saml2/config.py:464:23: E1135: Value '_logconf' doesn't support membership test (unsupported-membership-test) src/saml2/config.py:466:27: E1136: Value '_logconf' is unsubscriptable (unsubscriptable-object) src/saml2/config.py:481:50: E1136: Value '_logconf' is unsubscriptable (unsubscriptable-object) src/saml2/config.py:486:22: E1120: No value for argument 'filename' in constructor call (no-value-for-parameter) src/saml2/config.py:488:23: E1135: Value '_logconf' doesn't support membership test (unsupported-membership-test) src/saml2/config.py:489:42: E1136: Value '_logconf' is unsubscriptable (unsubscriptable-object) src/saml2/config.py:505:43: E1136: Value '_logconf' is unsubscriptable (unsubscriptable-object) src/saml2/config.py:552:19: E1136: Value 'self.virtual_organization' is unsubscriptable (unsubscriptable-object) ``` this seems right; the operations upon the Logger object do not make sense. There is no need to "fix" this, we just remove the relevant code. We should come back to this and refactor how the logger is configured for the library. Signed-off-by: Ivan Kanakarakis <[email protected]>
1 parent 24d248c commit 832d26f

File tree

4 files changed

+9
-113
lines changed

4 files changed

+9
-113
lines changed

src/saml2/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@
4040
import defusedxml.ElementTree
4141

4242

43-
root_logger = logging.getLogger(__name__)
44-
root_logger.level = logging.NOTSET
43+
logger = logging.getLogger(__name__)
4544

4645
NAMESPACE = 'urn:oasis:names:tc:SAML:2.0:assertion'
4746
# TEMPLATE = '{urn:oasis:names:tc:SAML:2.0:assertion}%s'

src/saml2/config.py

Lines changed: 6 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,20 @@
1010

1111
import six
1212

13-
from saml2 import root_logger, BINDING_URI, SAMLError
14-
from saml2 import BINDING_SOAP
15-
from saml2 import BINDING_HTTP_REDIRECT
16-
from saml2 import BINDING_HTTP_POST
1713
from saml2 import BINDING_HTTP_ARTIFACT
14+
from saml2 import BINDING_HTTP_POST
15+
from saml2 import BINDING_HTTP_REDIRECT
16+
from saml2 import BINDING_SOAP
17+
from saml2 import BINDING_URI
18+
from saml2 import SAMLError
1819

1920
from saml2.attribute_converter import ac_factory
2021
from saml2.assertion import Policy
2122
from saml2.mdstore import MetadataStore
2223
from saml2.saml import NAME_FORMAT_URI
2324
from saml2.virtual_org import VirtualOrg
2425

26+
2527
logger = logging.getLogger(__name__)
2628

2729
__author__ = 'rolandh'
@@ -47,7 +49,6 @@
4749
"contact_person",
4850
"name_form",
4951
"virtual_organization",
50-
"logger",
5152
"only_use_keys_in_metadata",
5253
"disable_ssl_certificate_validation",
5354
"preferred_binding",
@@ -211,7 +212,6 @@ def __init__(self, homedir="."):
211212
self.name_id_format = None
212213
self.name_id_format_allow_create = None
213214
self.virtual_organization = None
214-
self.logger = None
215215
self.only_use_keys_in_metadata = True
216216
self.logout_requests_signed = None
217217
self.disable_ssl_certificate_validation = None
@@ -453,63 +453,6 @@ def endpoint(self, service, binding=None, context=None):
453453
else:
454454
return unspec
455455

456-
def log_handler(self):
457-
try:
458-
_logconf = self.logger
459-
except KeyError:
460-
return None
461-
462-
handler = None
463-
for htyp in LOG_HANDLER:
464-
if htyp in _logconf:
465-
if htyp == "syslog":
466-
args = _logconf[htyp]
467-
if "socktype" in args:
468-
import socket
469-
if args["socktype"] == "dgram":
470-
args["socktype"] = socket.SOCK_DGRAM
471-
elif args["socktype"] == "stream":
472-
args["socktype"] = socket.SOCK_STREAM
473-
else:
474-
raise ConfigurationError("Unknown socktype!")
475-
try:
476-
handler = LOG_HANDLER[htyp](**args)
477-
except TypeError: # difference between 2.6 and 2.7
478-
del args["socktype"]
479-
handler = LOG_HANDLER[htyp](**args)
480-
else:
481-
handler = LOG_HANDLER[htyp](**_logconf[htyp])
482-
break
483-
484-
if handler is None:
485-
# default if rotating logger
486-
handler = LOG_HANDLER["rotating"]()
487-
488-
if "format" in _logconf:
489-
formatter = logging.Formatter(_logconf["format"])
490-
else:
491-
formatter = logging.Formatter(LOG_FORMAT)
492-
493-
handler.setFormatter(formatter)
494-
return handler
495-
496-
def setup_logger(self):
497-
if root_logger.level != logging.NOTSET: # Someone got there before me
498-
return root_logger
499-
500-
_logconf = self.logger
501-
if _logconf is None:
502-
return root_logger
503-
504-
try:
505-
root_logger.setLevel(LOG_LEVEL[_logconf["loglevel"].lower()])
506-
except KeyError: # reasonable default
507-
root_logger.setLevel(logging.INFO)
508-
509-
root_logger.addHandler(self.log_handler())
510-
root_logger.info("Logging started")
511-
return root_logger
512-
513456
def endpoint2service(self, endpoint, context=None):
514457
endps = self.getattr("endpoints", context)
515458

src/saml2/entity.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@ def __init__(self, entity_type, config=None, config_file="",
159159
vo.sp = self
160160

161161
self.metadata = self.config.metadata
162-
self.config.setup_logger()
163162
self.debug = self.config.debug
164163

165164
self.sec = security_context(self.config)

tests/test_31_config.py

Lines changed: 2 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from saml2 import BINDING_HTTP_REDIRECT, BINDING_SOAP, BINDING_HTTP_POST
99
from saml2.config import SPConfig, IdPConfig, Config
1010

11-
from saml2 import root_logger
11+
from saml2 import logger
1212

1313
from pathutils import dotname, full_path
1414
from saml2.sigver import security_context, CryptoBackendXMLSecurity
@@ -297,57 +297,12 @@ def test_wayf():
297297
assert name(ent) == 'Example Co.'
298298
assert name(ent, "se") == 'Exempel AB'
299299

300-
c.setup_logger()
301-
302-
assert root_logger.level != logging.NOTSET
303-
assert root_logger.level == logging.INFO
304-
assert len(root_logger.handlers) == 1
305-
assert isinstance(root_logger.handlers[0],
306-
logging.handlers.RotatingFileHandler)
307-
handler = root_logger.handlers[0]
308-
assert handler.backupCount == 5
309-
try:
310-
assert handler.maxBytes == 100000
311-
except AssertionError:
312-
assert handler.maxBytes == 500000
313-
assert handler.mode == "a"
314-
assert root_logger.name == "saml2"
315-
assert root_logger.level == 20
316-
317300

318301
def test_conf_syslog():
319302
c = SPConfig().load_file("server_conf_syslog")
320303
c.context = "sp"
321304

322-
# otherwise the logger setting is not changed
323-
root_logger.level = logging.NOTSET
324-
while root_logger.handlers:
325-
handler = root_logger.handlers[-1]
326-
root_logger.removeHandler(handler)
327-
handler.flush()
328-
handler.close()
329-
330-
print(c.logger)
331-
c.setup_logger()
332-
333-
assert root_logger.level != logging.NOTSET
334-
assert root_logger.level == logging.INFO
335-
assert len(root_logger.handlers) == 1
336-
assert isinstance(root_logger.handlers[0],
337-
logging.handlers.SysLogHandler)
338-
handler = root_logger.handlers[0]
339-
print(handler.__dict__)
340-
assert handler.facility == "local3"
341-
assert handler.address == ('localhost', 514)
342-
if ((sys.version_info.major == 2 and sys.version_info.minor >= 7) or
343-
sys.version_info.major > 2):
344-
assert handler.socktype == 2
345-
else:
346-
pass
347-
assert root_logger.name == "saml2"
348-
assert root_logger.level == 20
349-
350-
#noinspection PyUnresolvedReferences
305+
351306
def test_3():
352307
cnf = Config()
353308
cnf.load_file(dotname("sp_1_conf"))

0 commit comments

Comments
 (0)