Skip to content

Commit b4fd754

Browse files
committed
Support logging configuration through the python logger
Signed-off-by: Ivan Kanakarakis <[email protected]>
1 parent d62a10c commit b4fd754

File tree

3 files changed

+81
-34
lines changed

3 files changed

+81
-34
lines changed

docs/howto/config.rst

Lines changed: 49 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,55 @@ Configuration directives
6464
General directives
6565
------------------
6666

67+
logging
68+
^^^^^^^
69+
70+
The logging configuration format is the python logging format.
71+
The configuration is passed to the python logging dictionary configuration handler,
72+
directly.
73+
74+
Example::
75+
76+
"logging": {
77+
"version": 1,
78+
"formatters": {
79+
"simple": {
80+
"format": "[%(asctime)s] [%(levelname)s] [%(name)s.%(funcName)s] %(message)s",
81+
},
82+
},
83+
"handlers": {
84+
"stdout": {
85+
"class": "logging.StreamHandler",
86+
"stream": "ext://sys.stdout",
87+
"level": "DEBUG",
88+
"formatter": "simple",
89+
},
90+
},
91+
"loggers": {
92+
"saml2": {
93+
"level": "DEBUG"
94+
},
95+
},
96+
"root": {
97+
"level": "DEBUG",
98+
"handlers": [
99+
"stdout",
100+
],
101+
},
102+
},
103+
104+
The exapmle configuration above will enable DEBUG logging to stdout.
105+
106+
107+
debug
108+
^^^^^
109+
110+
Example::
111+
112+
debug: 1
113+
114+
Whether debug information should be sent to the log file.
115+
67116
additional_cert_files
68117
^^^^^^^^^^^^^^^^^^^^^
69118

@@ -186,15 +235,6 @@ and **other**.::
186235
},
187236
]
188237

189-
debug
190-
^^^^^
191-
192-
Example::
193-
194-
debug: 1
195-
196-
Whether debug information should be sent to the log file.
197-
198238
entityid
199239
^^^^^^^^
200240

example/idp2/idp_conf.py.example

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,33 @@ CONFIG = {
137137
# the identifier returned to a SP
138138
"xmlsec_binary": xmlsec_path,
139139
#"attribute_map_dir": "../attributemaps",
140-
"logger": {
141-
"rotating": {
142-
"filename": "idp.log",
143-
"maxBytes": 500000,
144-
"backupCount": 5,
140+
"logging": {
141+
"version": 1,
142+
"formatters": {
143+
"simple": {
144+
"format": "[%(asctime)s] [%(levelname)s] [%(name)s.%(funcName)s] %(message)s",
145+
},
146+
},
147+
"handlers": {
148+
"stdout": {
149+
"class": "logging.StreamHandler",
150+
"stream": "ext://sys.stdout",
151+
"level": "DEBUG",
152+
"formatter": "simple",
153+
},
145154
},
146-
"loglevel": "debug",
147-
}
155+
"loggers": {
156+
"saml2": {
157+
"level": "DEBUG"
158+
},
159+
},
160+
"root": {
161+
"level": "DEBUG",
162+
"handlers": [
163+
"stdout",
164+
],
165+
},
166+
},
148167
}
149168

150169
# Authentication contexts

src/saml2/config.py

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import os
88
import re
99
import sys
10+
from logging.config import dictConfig as configure_logging_by_dict
1011

1112
import six
1213

@@ -30,6 +31,7 @@
3031

3132

3233
COMMON_ARGS = [
34+
"logging",
3335
"debug",
3436
"entityid",
3537
"xmlsec_binary",
@@ -141,24 +143,6 @@
141143
"aq": COMMON_ARGS + COMPLEX_ARGS + AQ_ARGS,
142144
}
143145

144-
# --------------- Logging stuff ---------------
145-
146-
LOG_LEVEL = {
147-
'debug': logging.DEBUG,
148-
'info': logging.INFO,
149-
'warning': logging.WARNING,
150-
'error': logging.ERROR,
151-
'critical': logging.CRITICAL}
152-
153-
LOG_HANDLER = {
154-
"rotating": logging.handlers.RotatingFileHandler,
155-
"syslog": logging.handlers.SysLogHandler,
156-
"timerotate": logging.handlers.TimedRotatingFileHandler,
157-
"memory": logging.handlers.MemoryHandler,
158-
}
159-
160-
LOG_FORMAT = "%(asctime)s %(name)s:%(levelname)s %(message)s"
161-
162146
_RPA = [BINDING_HTTP_REDIRECT, BINDING_HTTP_POST, BINDING_HTTP_ARTIFACT]
163147
_PRA = [BINDING_HTTP_POST, BINDING_HTTP_REDIRECT, BINDING_HTTP_ARTIFACT]
164148
_SRPA = [BINDING_SOAP, BINDING_HTTP_REDIRECT, BINDING_HTTP_POST,
@@ -190,6 +174,7 @@ class Config(object):
190174
def_context = ""
191175

192176
def __init__(self, homedir="."):
177+
self.logging = None
193178
self._homedir = homedir
194179
self.entityid = None
195180
self.xmlsec_binary = None
@@ -362,6 +347,9 @@ def load(self, cnf, metadata_construction=False):
362347
except TypeError: # Something that can't be a string
363348
setattr(self, arg, cnf[arg])
364349

350+
if self.logging is not None:
351+
configure_logging_by_dict(self.logging)
352+
365353
if not self.delete_tmpfiles:
366354
logger.warning(
367355
"delete_tmpfiles is set to False; "

0 commit comments

Comments
 (0)