Skip to content

Commit ee29618

Browse files
Merge pull request #283 from sebulibah/attribute-mapping-logger
Improve logging - satosa.attribute_mapping
2 parents 65a1b47 + 70f5864 commit ee29618

File tree

1 file changed

+26
-12
lines changed

1 file changed

+26
-12
lines changed

src/satosa/attribute_mapping.py

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ def to_internal_filter(self, attribute_profile, external_attribute_names):
5858
try:
5959
profile_mapping = self.to_internal_attributes[attribute_profile]
6060
except KeyError:
61-
logger.warn("no attribute mapping found for the given attribute profile '%s'", attribute_profile)
61+
logline = "no attribute mapping found for the given attribute profile {}".format(attribute_profile)
62+
logger.warn(logline)
6263
# no attributes since the given profile is not configured
6364
return []
6465

@@ -88,21 +89,27 @@ def to_internal(self, attribute_profile, external_dict):
8889

8990
for internal_attribute_name, mapping in self.from_internal_attributes.items():
9091
if attribute_profile not in mapping:
91-
logger.debug("no attribute mapping found for internal attribute '%s' the attribute profile '%s'" % (
92-
internal_attribute_name, attribute_profile))
92+
logline = "no attribute mapping found for internal attribute {internal} the attribute profile {attribute}".format(
93+
internal=internal_attribute_name, attribute=attribute_profile
94+
)
95+
logger.debug(logline)
9396
# skip this internal attribute if we have no mapping in the specified profile
9497
continue
9598

9699
external_attribute_name = mapping[attribute_profile]
97100
attribute_values = self._collate_attribute_values_by_priority_order(external_attribute_name,
98101
external_dict)
99102
if attribute_values: # Only insert key if it has some values
100-
logger.debug("backend attribute '%s' mapped to %s" % (external_attribute_name,
101-
internal_attribute_name))
103+
logline = "backend attribute {external} mapped to {internal}".format(
104+
external=external_attribute_name, internal=internal_attribute_name
105+
)
106+
logger.debug(logline)
102107
internal_dict[internal_attribute_name] = attribute_values
103108
else:
104-
logger.debug("skipped backend attribute '%s': no value found", external_attribute_name)
105-
109+
logline = "skipped backend attribute {}: no value found".format(
110+
external_attribute_name
111+
)
112+
logger.debug(logline)
106113
internal_dict = self._handle_template_attributes(attribute_profile, internal_dict)
107114
return internal_dict
108115

@@ -181,20 +188,27 @@ def from_internal(self, attribute_profile, internal_dict):
181188
try:
182189
attribute_mapping = self.from_internal_attributes[internal_attribute_name]
183190
except KeyError:
184-
logger.debug("no attribute mapping found for the internal attribute '%s'", internal_attribute_name)
191+
logline = "no attribute mapping found for the internal attribute {}".format(
192+
internal_attribute_name
193+
)
194+
logger.debug(logline)
185195
continue
186196

187197
if attribute_profile not in attribute_mapping:
188198
# skip this internal attribute if we have no mapping in the specified profile
189-
logger.debug("no mapping found for '%s' in attribute profile '%s'" %
190-
(internal_attribute_name, attribute_profile))
199+
logline = "no mapping found for '{internal}' in attribute profile '{attribute}'".format(
200+
internal=internal_attribute_name, attribute=attribute_profile
201+
)
202+
logger.debug(logline)
191203
continue
192204

193205
external_attribute_names = self.from_internal_attributes[internal_attribute_name][attribute_profile]
194206
# select the first attribute name
195207
external_attribute_name = external_attribute_names[0]
196-
logger.debug("frontend attribute %s mapped from %s" % (external_attribute_name,
197-
internal_attribute_name))
208+
logline = "frontend attribute {external} mapped from {internal}".format(
209+
external=external_attribute_name, internal=internal_attribute_name
210+
)
211+
logger.debug(logline)
198212

199213
if self.separator in external_attribute_name:
200214
nested_attribute_names = external_attribute_name.split(self.separator)

0 commit comments

Comments
 (0)