diff options
author | Jozef Knaperek <jknaperek@gmail.com> | 2015-10-12 16:22:19 +0200 |
---|---|---|
committer | Jozef Knaperek <jknaperek@gmail.com> | 2015-10-15 15:33:10 +0200 |
commit | c7febbf9e8c85355dccb53a326a51bfc41db1c66 (patch) | |
tree | 976664df2088314a431be719f64359448ddf17e9 /src/saml2test | |
parent | 1228db66eb006e0f069cc1b6b1612c6cbaa8df1d (diff) | |
download | pysaml2-c7febbf9e8c85355dccb53a326a51bfc41db1c66.tar.gz |
Fix paramter passing in logging messages
Pass parameters into logger calls directly instead of pre-merging
with the logger message. This way the logs are easier to maintain
and process. The code is also faster when logging is turned off
since it doesn't have to evaluate all params and render them into
strings.
Diffstat (limited to 'src/saml2test')
-rw-r--r-- | src/saml2test/interaction.py | 14 | ||||
-rw-r--r-- | src/saml2test/opfunc.py | 16 | ||||
-rw-r--r-- | src/saml2test/tool.py | 32 |
3 files changed, 30 insertions, 32 deletions
diff --git a/src/saml2test/interaction.py b/src/saml2test/interaction.py index ddfbeacb..941399e6 100644 --- a/src/saml2test/interaction.py +++ b/src/saml2test/interaction.py @@ -102,7 +102,7 @@ class Interaction(object): self.who = "Form process" def pick_interaction(self, _base="", content="", req=None): - logger.info("pick_interaction baseurl: %s" % _base) + logger.info("pick_interaction baseurl: %s", _base) unic = content if content: _bs = BeautifulSoup(content) @@ -113,11 +113,11 @@ class Interaction(object): _match = 0 for attr, val in interaction["matches"].items(): if attr == "url": - logger.info("matching baseurl against: %s" % val) + logger.info("matching baseurl against: %s", val) if val == _base: _match += 1 elif attr == "title": - logger.info("matching '%s' against title" % val) + logger.info("matching '%s' against title", val) if _bs is None: break if _bs.title is None: @@ -140,7 +140,7 @@ class Interaction(object): _match += 1 if _match == len(interaction["matches"]): - logger.info("Matched: %s" % interaction["matches"]) + logger.info("Matched: %s", interaction["matches"]) return interaction raise InteractionNeeded("No interaction matched") @@ -319,7 +319,7 @@ class Interaction(object): else: url = path - logger.info("GET %s" % url) + logger.info("GET %s", url) return self.httpc.send(url, "GET") #return resp, "" @@ -390,8 +390,8 @@ class Action(object): _args.update({"location": location, "features": features, "conv": conv}) - logger.info("<-- FUNCTION: %s" % function.__name__) - logger.info("<-- ARGS: %s" % _args) + logger.info("<-- FUNCTION: %s", function.__name__) + logger.info("<-- ARGS: %s", _args) result = function(response, **_args) self.post_op(result, conv, _args) diff --git a/src/saml2test/opfunc.py b/src/saml2test/opfunc.py index 2d612edc..014f93ba 100644 --- a/src/saml2test/opfunc.py +++ b/src/saml2test/opfunc.py @@ -109,17 +109,17 @@ def do_request(client, url, method, body="", headers=None): if headers is None: headers = {} - logger.info("--> URL: %s" % url) - logger.info("--> BODY: %s" % body) - logger.info("--> Headers: %s" % (headers,)) + logger.info("--> URL: %s", url) + logger.info("--> BODY: %s", body) + logger.info("--> Headers: %s", headers) response = client.http_request(url, method=method, data=body, headers=headers) - logger.info("<-- RESPONSE: %s" % response) - logger.info("<-- CONTENT: %s" % response.text) + logger.info("<-- RESPONSE: %s", response) + logger.info("<-- CONTENT: %s", response.text) if response.cookies: - logger.info("<-- COOKIES: %s" % response.cookies) + logger.info("<-- COOKIES: %s", response.cookies) return url, response, response.text @@ -366,8 +366,8 @@ class Operation(object): _args["location"] = location - logger.info("--> FUNCTION: %s" % self.function.__name__) - logger.info("--> ARGS: %s" % (_args,)) + logger.info("--> FUNCTION: %s", self.function.__name__) + logger.info("--> ARGS: %s", _args) result = self.function(self.conv.client, response, content, **_args) self.post_op(result, self.conv, _args) diff --git a/src/saml2test/tool.py b/src/saml2test/tool.py index d9113599..da96c336 100644 --- a/src/saml2test/tool.py +++ b/src/saml2test/tool.py @@ -51,14 +51,14 @@ class Conversation(object): def check_severity(self, stat): if stat["status"] >= 4: - logger.error("WHERE: %s" % stat["id"]) - logger.error("STATUS:%s" % STATUSCODE[stat["status"]]) + logger.error("WHERE: %s", stat["id"]) + logger.error("STATUS:%s", STATUSCODE[stat["status"]]) try: - logger.error("HTTP STATUS: %s" % stat["http_status"]) + logger.error("HTTP STATUS: %s", stat["http_status"]) except KeyError: pass try: - logger.error("INFO: %s" % stat["message"]) + logger.error("INFO: %s", stat["message"]) except KeyError: pass @@ -119,8 +119,7 @@ class Conversation(object): raise FatalError( "Too long sequence of redirects: %s" % rdseq) - logger.info("HTTP %d Location: %s" % (_response.status_code, - url)) + logger.info("HTTP %d Location: %s", _response.status_code, url) # If back to me for_me = False for redirect_uri in self.my_endpoints(): @@ -143,13 +142,13 @@ class Conversation(object): break else: try: - logger.info("GET %s" % url) + logger.info("GET %s", url) _response = self.client.send(url, "GET") except Exception as err: raise FatalError("%s" % err) content = _response.text - logger.info("<-- CONTENT: %s" % content) + logger.info("<-- CONTENT: %s", content) self.position = url self.last_content = content self.response = _response @@ -169,15 +168,15 @@ class Conversation(object): self.position = url cnt = content.replace("\n", '').replace("\t", '').replace("\r", '') - logger.error("URL: %s" % url) - logger.error("Page Content: %s" % cnt) + logger.error("URL: %s", url) + logger.error("Page Content: %s", cnt) raise except KeyError: self.position = url cnt = content.replace("\n", '').replace("\t", '').replace("\r", '') - logger.error("URL: %s" % url) - logger.error("Page Content: %s" % cnt) + logger.error("URL: %s", url) + logger.error("Page Content: %s", cnt) self.err_check("interaction-needed") if _spec == _last_action: @@ -194,7 +193,7 @@ class Conversation(object): _last_action = _spec if len(_spec) > 2: - logger.info(">> %s <<" % _spec["page-type"]) + logger.info(">> %s <<", _spec["page-type"]) if _spec["page-type"] == "login": self.login_page = content @@ -213,12 +212,11 @@ class Conversation(object): self.response = _response if _response.status_code >= 400: - txt = "Got status code '%s', error: %s" % ( - _response.status_code, content) - logger.error(txt) + txt = "Got status code '%s', error: %s" + logger.error(txt, _response.status_code, content) self.test_output.append( {"status": ERROR, - "message": txt, + "message": txt % (_response.status_code, content), #"id": "exception", #"name": "interaction needed", "url": self.position}) |