diff options
author | Ivan Kanakarakis <ivan.kanak@gmail.com> | 2020-09-29 14:36:41 +0300 |
---|---|---|
committer | Ivan Kanakarakis <ivan.kanak@gmail.com> | 2020-09-29 14:41:48 +0300 |
commit | b4fd75475638c3318dfd00ea6cf0c2a56504a444 (patch) | |
tree | d0676b6b04a1d36b3ba546e8c76e771a22e96603 | |
parent | d62a10c473f64e389d2d26958c83c83daafe38fd (diff) | |
download | pysaml2-b4fd75475638c3318dfd00ea6cf0c2a56504a444.tar.gz |
Support logging configuration through the python logger
Signed-off-by: Ivan Kanakarakis <ivan.kanak@gmail.com>
-rw-r--r-- | docs/howto/config.rst | 58 | ||||
-rw-r--r-- | example/idp2/idp_conf.py.example | 33 | ||||
-rw-r--r-- | src/saml2/config.py | 24 |
3 files changed, 81 insertions, 34 deletions
diff --git a/docs/howto/config.rst b/docs/howto/config.rst index c4279974..060f4f68 100644 --- a/docs/howto/config.rst +++ b/docs/howto/config.rst @@ -64,6 +64,55 @@ Configuration directives General directives ------------------ +logging +^^^^^^^ + +The logging configuration format is the python logging format. +The configuration is passed to the python logging dictionary configuration handler, +directly. + +Example:: + + "logging": { + "version": 1, + "formatters": { + "simple": { + "format": "[%(asctime)s] [%(levelname)s] [%(name)s.%(funcName)s] %(message)s", + }, + }, + "handlers": { + "stdout": { + "class": "logging.StreamHandler", + "stream": "ext://sys.stdout", + "level": "DEBUG", + "formatter": "simple", + }, + }, + "loggers": { + "saml2": { + "level": "DEBUG" + }, + }, + "root": { + "level": "DEBUG", + "handlers": [ + "stdout", + ], + }, + }, + +The exapmle configuration above will enable DEBUG logging to stdout. + + +debug +^^^^^ + +Example:: + + debug: 1 + +Whether debug information should be sent to the log file. + additional_cert_files ^^^^^^^^^^^^^^^^^^^^^ @@ -186,15 +235,6 @@ and **other**.:: }, ] -debug -^^^^^ - -Example:: - - debug: 1 - -Whether debug information should be sent to the log file. - entityid ^^^^^^^^ diff --git a/example/idp2/idp_conf.py.example b/example/idp2/idp_conf.py.example index bc863112..17f81d9f 100644 --- a/example/idp2/idp_conf.py.example +++ b/example/idp2/idp_conf.py.example @@ -137,14 +137,33 @@ CONFIG = { # the identifier returned to a SP "xmlsec_binary": xmlsec_path, #"attribute_map_dir": "../attributemaps", - "logger": { - "rotating": { - "filename": "idp.log", - "maxBytes": 500000, - "backupCount": 5, + "logging": { + "version": 1, + "formatters": { + "simple": { + "format": "[%(asctime)s] [%(levelname)s] [%(name)s.%(funcName)s] %(message)s", + }, + }, + "handlers": { + "stdout": { + "class": "logging.StreamHandler", + "stream": "ext://sys.stdout", + "level": "DEBUG", + "formatter": "simple", + }, }, - "loglevel": "debug", - } + "loggers": { + "saml2": { + "level": "DEBUG" + }, + }, + "root": { + "level": "DEBUG", + "handlers": [ + "stdout", + ], + }, + }, } # Authentication contexts diff --git a/src/saml2/config.py b/src/saml2/config.py index dbf57aa3..eb00c7cf 100644 --- a/src/saml2/config.py +++ b/src/saml2/config.py @@ -7,6 +7,7 @@ import logging.handlers import os import re import sys +from logging.config import dictConfig as configure_logging_by_dict import six @@ -30,6 +31,7 @@ __author__ = 'rolandh' COMMON_ARGS = [ + "logging", "debug", "entityid", "xmlsec_binary", @@ -141,24 +143,6 @@ SPEC = { "aq": COMMON_ARGS + COMPLEX_ARGS + AQ_ARGS, } -# --------------- Logging stuff --------------- - -LOG_LEVEL = { - 'debug': logging.DEBUG, - 'info': logging.INFO, - 'warning': logging.WARNING, - 'error': logging.ERROR, - 'critical': logging.CRITICAL} - -LOG_HANDLER = { - "rotating": logging.handlers.RotatingFileHandler, - "syslog": logging.handlers.SysLogHandler, - "timerotate": logging.handlers.TimedRotatingFileHandler, - "memory": logging.handlers.MemoryHandler, -} - -LOG_FORMAT = "%(asctime)s %(name)s:%(levelname)s %(message)s" - _RPA = [BINDING_HTTP_REDIRECT, BINDING_HTTP_POST, BINDING_HTTP_ARTIFACT] _PRA = [BINDING_HTTP_POST, BINDING_HTTP_REDIRECT, BINDING_HTTP_ARTIFACT] _SRPA = [BINDING_SOAP, BINDING_HTTP_REDIRECT, BINDING_HTTP_POST, @@ -190,6 +174,7 @@ class Config(object): def_context = "" def __init__(self, homedir="."): + self.logging = None self._homedir = homedir self.entityid = None self.xmlsec_binary = None @@ -362,6 +347,9 @@ class Config(object): except TypeError: # Something that can't be a string setattr(self, arg, cnf[arg]) + if self.logging is not None: + configure_logging_by_dict(self.logging) + if not self.delete_tmpfiles: logger.warning( "delete_tmpfiles is set to False; " |