Skip to content

Commit 1a5a0a0

Browse files
Use more performant version of Python logging calls (#1205)
* log.debug: Use separate arguments not format() It's much more performant to avoid format() strings when generating logging messages. * log.info: Use separate arguments not format() * log.error/log.warning: Use separate arguments not format() --------- Co-authored-by: Gonchik Tsymzhitov <gonchik.tsymzhitov@gmail.com>
1 parent fb5f845 commit 1a5a0a0

File tree

4 files changed

+39
-42
lines changed

4 files changed

+39
-42
lines changed

atlassian/bitbucket/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def all_project_administrators(self):
6565
:return: A generator object containing a map with the project_key, project_name and project_administrators
6666
"""
6767
for project in self.project_list():
68-
log.info("Processing project: {0} - {1}".format(project.get("key"), project.get("name")))
68+
log.info("Processing project: %s - %s", project.get("key"), project.get("name"))
6969
yield {
7070
"project_key": project.get("key"),
7171
"project_name": project.get("name"),

atlassian/confluence.py

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ def get_page_by_title(self, space, title, start=0, limit=1, expand=None, type="p
313313
try:
314314
return response.get("results")[0]
315315
except (IndexError, TypeError) as e:
316-
log.error("Can't find '{title}' page on the {url}!".format(title=title, url=self.url))
316+
log.error("Can't find '%s' page on the %s!", title, self.url)
317317
log.debug(e)
318318
return None
319319

@@ -745,7 +745,7 @@ def create_page(
745745
:param full_width: DEFAULT: False
746746
:return:
747747
"""
748-
log.info('Creating {type} "{space}" -> "{title}"'.format(space=space, title=title, type=type))
748+
log.info('Creating %s "%s" -> "%s"', type, space, title)
749749
url = "rest/api/content/"
750750
data = {
751751
"type": type,
@@ -1302,12 +1302,12 @@ def remove_page_attachment_keep_version(self, page_id, filename, keep_last_versi
13021302
version=remove_version_attachment_number,
13031303
)
13041304
log.info(
1305-
"Removed oldest version for {}, now versions equal more than {}".format(
1306-
attachment.get("title"), len(attachment_versions)
1307-
)
1305+
"Removed oldest version for %s, now versions equal more than %s",
1306+
attachment.get("title"),
1307+
len(attachment_versions),
13081308
)
13091309
attachment_versions = self.get_attachment_history(attachment.get("id"))
1310-
log.info("Kept versions {} for {}".format(keep_last_versions, attachment.get("title")))
1310+
log.info("Kept versions %s for %s", keep_last_versions, attachment.get("title"))
13111311

13121312
def get_attachment_history(self, attachment_id, limit=200, start=0):
13131313
"""
@@ -1506,8 +1506,8 @@ def remove_page_history_keep_version(self, page_id, keep_last_versions):
15061506
self.remove_page_history(page_id=page_id, version_number=1)
15071507
page = self.get_page_by_id(page_id=page_id, expand="version")
15081508
page_number = page.get("version").get("number")
1509-
log.info("Removed oldest version for {}, now it's {}".format(page.get("title"), page_number))
1510-
log.info("Kept versions {} for {}".format(keep_last_versions, page.get("title")))
1509+
log.info("Removed oldest version for %s, now it's %s", page.get("title"), page_number)
1510+
log.info("Kept versions %s for %s", keep_last_versions, page.get("title"))
15111511

15121512
def has_unknown_attachment_error(self, page_id):
15131513
"""
@@ -1536,7 +1536,7 @@ def is_page_content_is_already_updated(self, page_id, body, title=None):
15361536
if title:
15371537
current_title = confluence_content.get("title", None)
15381538
if title != current_title:
1539-
log.info("Title of {page_id} is different".format(page_id=page_id))
1539+
log.info("Title of %s is different", page_id)
15401540
return False
15411541

15421542
if self.advanced_mode:
@@ -1554,14 +1554,14 @@ def is_page_content_is_already_updated(self, page_id, body, title=None):
15541554
# @todo move into utils
15551555
confluence_body_content = utils.symbol_normalizer(confluence_body_content)
15561556

1557-
log.debug('Old Content: """{body}"""'.format(body=confluence_body_content))
1558-
log.debug('New Content: """{body}"""'.format(body=body))
1557+
log.debug('Old Content: """%s"""', confluence_body_content)
1558+
log.debug('New Content: """%s"""', body)
15591559

15601560
if confluence_body_content.strip() == body.strip():
1561-
log.info("Content of {page_id} is exactly the same".format(page_id=page_id))
1561+
log.info("Content of %s is exactly the same", page_id)
15621562
return True
15631563
else:
1564-
log.info("Content of {page_id} differs".format(page_id=page_id))
1564+
log.info("Content of %s differs", page_id)
15651565
return False
15661566

15671567
def update_existing_page(
@@ -1617,7 +1617,7 @@ def update_page(
16171617
"""
16181618
# update current page
16191619
params = {"status": "current"}
1620-
log.info('Updating {type} "{title}" with {parent_id}'.format(title=title, type=type, parent_id=parent_id))
1620+
log.info('Updating %s "%s" with %s', type, title, parent_id)
16211621

16221622
if not always_update and body is not None and self.is_page_content_is_already_updated(page_id, body, title):
16231623
return self.get_page_by_id(page_id)
@@ -1628,7 +1628,7 @@ def update_page(
16281628
else:
16291629
version = self.history(page_id)["lastUpdated"]["number"] + 1
16301630
except (IndexError, TypeError) as e:
1631-
log.error("Can't find '{title}' {type}!".format(title=title, type=type))
1631+
log.error("Can't find '%s' %s!", title, type)
16321632
log.debug(e)
16331633
return None
16341634

@@ -1699,7 +1699,7 @@ def _insert_to_existing_page(
16991699
:param top_of_page: Option to add the content to the end of page body
17001700
:return:
17011701
"""
1702-
log.info('Updating {type} "{title}"'.format(title=title, type=type))
1702+
log.info('Updating %s "%s"', type, title)
17031703
# update current page
17041704
params = {"status": "current"}
17051705

@@ -1768,7 +1768,7 @@ def append_page(
17681768
If False then notifications will be sent.
17691769
:return:
17701770
"""
1771-
log.info('Updating {type} "{title}"'.format(title=title, type=type))
1771+
log.info('Updating %s "%s"', type, title)
17721772

17731773
return self._insert_to_existing_page(
17741774
page_id,
@@ -1803,7 +1803,7 @@ def prepend_page(
18031803
If False then notifications will be sent.
18041804
:return:
18051805
"""
1806-
log.info('Updating {type} "{title}"'.format(title=title, type=type))
1806+
log.info('Updating %s "%s"', type, title)
18071807

18081808
return self._insert_to_existing_page(
18091809
page_id,
@@ -1866,10 +1866,9 @@ def update_or_create(
18661866
)
18671867

18681868
log.info(
1869-
"You may access your page at: {host}{url}".format(
1870-
host=self.url,
1871-
url=((result or {}).get("_links") or {}).get("tinyui"),
1872-
)
1869+
"You may access your page at: %s%s",
1870+
self.url,
1871+
((result or {}).get("_links") or {}).get("tinyui"),
18731872
)
18741873
return result
18751874

atlassian/jira.py

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -492,13 +492,13 @@ def get_component_related_issues(self, component_id):
492492
return self.get(url)
493493

494494
def create_component(self, component):
495-
log.warning('Creating component "{name}"'.format(name=component["name"]))
495+
log.warning('Creating component "%s"', component["name"])
496496
base_url = self.resource_url("component")
497497
url = "{base_url}/".format(base_url=base_url)
498498
return self.post(url, data=component)
499499

500500
def delete_component(self, component_id):
501-
log.warning('Deleting component "{component_id}"'.format(component_id=component_id))
501+
log.warning('Deleting component "%s"', component_id)
502502
base_url = self.resource_url("component")
503503
return self.delete("{base_url}/{component_id}".format(base_url=base_url, component_id=component_id))
504504

@@ -1249,20 +1249,20 @@ def issue_exists(self, issue_key):
12491249
try:
12501250
resp = self.issue(issue_key, fields="*none")
12511251
if resp.status_code == 404:
1252-
log.info('Issue "{issue_key}" does not exists'.format(issue_key=issue_key))
1252+
log.info('Issue "%s" does not exists', issue_key)
12531253
return False
12541254
resp.raise_for_status()
1255-
log.info('Issue "{issue_key}" exists'.format(issue_key=issue_key))
1255+
log.info('Issue "%s" exists', issue_key)
12561256
return True
12571257
finally:
12581258
self.advanced_mode = original_value
12591259

12601260
def issue_deleted(self, issue_key):
12611261
exists = self.issue_exists(issue_key)
12621262
if exists:
1263-
log.info('Issue "{issue_key}" is not deleted'.format(issue_key=issue_key))
1263+
log.info('Issue "%s" is not deleted', issue_key)
12641264
else:
1265-
log.info('Issue "{issue_key}" is deleted'.format(issue_key=issue_key))
1265+
log.info('Issue "%s" is deleted', issue_key)
12661266
return not exists
12671267

12681268
def delete_issue(self, issue_id_or_key, delete_subtasks=True):
@@ -1283,13 +1283,13 @@ def delete_issue(self, issue_id_or_key, delete_subtasks=True):
12831283
else:
12841284
params["deleteSubtasks"] = "false"
12851285

1286-
log.warning("Removing issue {}...".format(issue_id_or_key))
1286+
log.warning("Removing issue %s...", issue_id_or_key)
12871287

12881288
return self.delete(url, params=params)
12891289

12901290
# @todo merge with edit_issue method
12911291
def issue_update(self, issue_key, fields):
1292-
log.warning('Updating issue "{issue_key}" with "{fields}"'.format(issue_key=issue_key, fields=fields))
1292+
log.warning('Updating issue "%s" with "%s"', issue_key, fields)
12931293
base_url = self.resource_url("issue")
12941294
url = "{base_url}/{issue_key}".format(base_url=base_url, issue_key=issue_key)
12951295
return self.put(url, data={"fields": fields})
@@ -1323,7 +1323,7 @@ def issue_add_watcher(self, issue_key, user):
13231323
:param user:
13241324
:return:
13251325
"""
1326-
log.warning('Adding user {user} to "{issue_key}" watchers'.format(issue_key=issue_key, user=user))
1326+
log.warning('Adding user %s to "%s" watchers', user, issue_key)
13271327
data = user
13281328
base_url = self.resource_url("issue")
13291329
return self.post(
@@ -1338,7 +1338,7 @@ def issue_delete_watcher(self, issue_key, user):
13381338
:param user:
13391339
:return:
13401340
"""
1341-
log.warning('Deleting user {user} from "{issue_key}" watchers'.format(issue_key=issue_key, user=user))
1341+
log.warning('Deleting user %s from "%s" watchers', user, issue_key)
13421342
params = {"username": user}
13431343
base_url = self.resource_url("issue")
13441344
return self.delete(
@@ -1424,7 +1424,7 @@ def create_issues(self, list_of_issues_data):
14241424

14251425
# @todo refactor and merge with create_issue method
14261426
def issue_create(self, fields):
1427-
log.warning('Creating issue "{summary}"'.format(summary=fields["summary"]))
1427+
log.warning('Creating issue "%s"', fields["summary"])
14281428
url = self.resource_url("issue")
14291429
return self.post(url, data={"fields": fields})
14301430

@@ -1437,10 +1437,10 @@ def issue_create_or_update(self, fields):
14371437
return self.issue_create(fields)
14381438

14391439
if self.issue_deleted(issue_key):
1440-
log.warning('Issue "{issue_key}" deleted, skipping'.format(issue_key=issue_key))
1440+
log.warning('Issue "%s" deleted, skipping', issue_key)
14411441
return None
14421442

1443-
log.info('Issue "{issue_key}" exists, will update'.format(issue_key=issue_key))
1443+
log.info('Issue "%s" exists, will update', issue_key)
14441444
fields.pop("issuekey", None)
14451445
return self.issue_update(issue_key, fields)
14461446

@@ -1804,7 +1804,7 @@ def user_create(self, username, email, display_name, password=None, notification
18041804
Default:false.
18051805
:return:
18061806
"""
1807-
log.warning("Creating user {}".format(display_name))
1807+
log.warning("Creating user %s", display_name)
18081808
data = {
18091809
"name": username,
18101810
"emailAddress": email,
@@ -2771,9 +2771,7 @@ def create_issue_link(self, data):
27712771
}
27722772
:return:
27732773
"""
2774-
log.info(
2775-
"Linking issue {inward} and {outward}".format(inward=data["inwardIssue"], outward=data["outwardIssue"])
2776-
)
2774+
log.info("Linking issue %s and %s", data["inwardIssue"], data["outwardIssue"])
27772775
url = self.resource_url("issueLink")
27782776
return self.post(url, data=data)
27792777

atlassian/rest_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,8 @@ def request(
249249
)
250250
response.encoding = "utf-8"
251251

252-
log.debug("HTTP: {} {} -> {} {}".format(method, path, response.status_code, response.reason))
253-
log.debug("HTTP: Response text -> {}".format(response.text))
252+
log.debug("HTTP: %s %s -> %s %s", method, path, response.status_code, response.reason)
253+
log.debug("HTTP: Response text -> %s", response.text)
254254
if self.advanced_mode or advanced_mode:
255255
return response
256256

0 commit comments

Comments
 (0)