Skip to content

Commit 5cb3ba6

Browse files
humitosagjohnson
authored andcommitted
Organize logging levels (#3893)
* Organize logging levels Log only what we need as ERROR when it's something that we need/want to take a look that something could be a bug/issue. There are some ERROR that were replaced by WARNING since they are some failures but that we don't need to take a look and the message shown to the user should be enough for them. * Fix lint issues * Use the proper exc_info instead of custom formatting
1 parent f504d9d commit 5cb3ba6

File tree

22 files changed

+196
-106
lines changed

22 files changed

+196
-106
lines changed

readthedocs/builds/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ def clean_build_path(self):
247247
try:
248248
path = self.get_build_path()
249249
if path is not None:
250-
log.debug('Removing build path {0} for {1}'.format(path, self))
250+
log.debug('Removing build path %s for %s', path, self)
251251
rmtree(path)
252252
except OSError:
253253
log.exception('Build path cleanup failed')

readthedocs/builds/syncers.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ def copy(cls, path, target, is_file=False, **__):
5858
mkdir_cmd = ("ssh %s@%s mkdir -p %s" % (sync_user, server, target))
5959
ret = os.system(mkdir_cmd)
6060
if ret != 0:
61-
log.info("COPY ERROR to app servers:")
62-
log.info(mkdir_cmd)
61+
log.error("Copy error to app servers: cmd=%s", mkdir_cmd)
6362
if is_file:
6463
slash = ""
6564
else:
@@ -75,8 +74,7 @@ def copy(cls, path, target, is_file=False, **__):
7574
target=target))
7675
ret = os.system(sync_cmd)
7776
if ret != 0:
78-
log.info("COPY ERROR to app servers.")
79-
log.info(sync_cmd)
77+
log.error("Copy error to app servers: cmd=%s", sync_cmd)
8078

8179

8280
class DoubleRemotePuller(object):
@@ -100,8 +98,7 @@ def copy(cls, path, target, host, is_file=False, **__):
10098
)
10199
ret = os.system(mkdir_cmd)
102100
if ret != 0:
103-
log.info("MKDIR ERROR to app servers:")
104-
log.info(mkdir_cmd)
101+
log.error("MkDir error to app servers: cmd=%s", mkdir_cmd)
105102
# Add a slash when copying directories
106103
sync_cmd = (
107104
"ssh {user}@{server} 'rsync -av "
@@ -114,8 +111,7 @@ def copy(cls, path, target, host, is_file=False, **__):
114111
target=target))
115112
ret = os.system(sync_cmd)
116113
if ret != 0:
117-
log.info("COPY ERROR to app servers.")
118-
log.info(sync_cmd)
114+
log.error("Copy error to app servers: cmd=%s", sync_cmd)
119115

120116

121117
class RemotePuller(object):
@@ -142,7 +138,11 @@ def copy(cls, path, target, host, is_file=False, **__):
142138
)
143139
ret = os.system(sync_cmd)
144140
if ret != 0:
145-
log.error("COPY ERROR to app servers. Command: [{}] Return: [{}]".format(sync_cmd, ret))
141+
log.error(
142+
"Copy error to app servers. Command: [%s] Return: [%s]",
143+
sync_cmd,
144+
ret,
145+
)
146146

147147

148148
class Syncer(SettingsOverrideObject):

readthedocs/core/management/commands/clean_builds.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,19 @@ def handle(self, *args, **options):
4444
version = Version.objects.get(id=build['version'])
4545
latest_build = version.builds.latest('date')
4646
if latest_build.date > max_date:
47-
log.warning('{0} is newer than {1}'.format(
48-
latest_build, max_date))
47+
log.warning(
48+
'%s is newer than %s',
49+
latest_build,
50+
max_date,
51+
)
4952
path = version.get_build_path()
5053
if path is not None:
5154
log.info(
52-
('Found stale build path for {0} '
53-
'at {1}, last used on {2}').format(
54-
version, path, latest_build.date))
55+
'Found stale build path for %s at %s, last used on %s',
56+
version,
57+
path,
58+
latest_build.date,
59+
)
5560
if not options['dryrun']:
5661
version.clean_build_path()
5762
except Version.DoesNotExist:

readthedocs/core/management/commands/reindex_elasticsearch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,4 @@ def handle(self, *args, **options):
5353
update_search(version.pk, commit,
5454
delete_non_commit_files=False)
5555
except Exception:
56-
log.exception('Reindex failed for {}'.format(version))
56+
log.exception('Reindex failed for %s', version)

readthedocs/core/signals.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,9 @@ def decide_if_cors(sender, request, **kwargs): # pylint: disable=unused-argumen
5757
project = Project.objects.get(slug=project_slug)
5858
except Project.DoesNotExist:
5959
log.warning(
60-
'Invalid project passed to domain. [{project}:{domain}'.format(
61-
project=project_slug,
62-
domain=host,
63-
)
60+
'Invalid project passed to domain. [%s:%s]',
61+
project_slug,
62+
host,
6463
)
6564
return False
6665

readthedocs/core/views/hooks.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -233,12 +233,13 @@ def gitlab_build(request): # noqa: D205
233233
log.info(
234234
'GitLab webhook search: url=%s branches=%s',
235235
search_url,
236-
branches
236+
branches,
237237
)
238238
projects = get_project_from_url(search_url)
239239
if projects:
240240
return _build_url(search_url, projects, branches)
241-
log.error('Project match not found: url=%s', search_url)
241+
242+
log.info('Project match not found: url=%s', search_url)
242243
return HttpResponseNotFound('Project match not found')
243244
return HttpResponse('Method not allowed, POST is required', status=405)
244245

@@ -294,7 +295,7 @@ def bitbucket_build(request):
294295
log.info(
295296
'Bitbucket webhook search: url=%s branches=%s',
296297
search_url,
297-
branches
298+
branches,
298299
)
299300
log.debug('Bitbucket webhook payload:\n\n%s\n\n', data)
300301
projects = get_project_from_url(search_url)
@@ -304,10 +305,10 @@ def bitbucket_build(request):
304305
log.error(
305306
'Commit/branch not found url=%s branches=%s',
306307
search_url,
307-
branches
308+
branches,
308309
)
309310
return HttpResponseNotFound('Commit/branch not found')
310-
log.error('Project match not found: url=%s', search_url)
311+
log.info('Project match not found: url=%s', search_url)
311312
return HttpResponseNotFound('Project match not found')
312313
return HttpResponse('Method not allowed, POST is required', status=405)
313314

readthedocs/doc_builder/environments.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -445,12 +445,12 @@ def handle_exception(self, exc_type, exc_value, _):
445445
a failure and the context will be gracefully exited.
446446
"""
447447
if exc_type is not None:
448-
log.error(LOG_TEMPLATE
449-
.format(project=self.project.slug,
450-
version=self.version.slug,
451-
msg=exc_value),
452-
exc_info=True)
453448
if not issubclass(exc_type, BuildEnvironmentWarning):
449+
log.error(LOG_TEMPLATE
450+
.format(project=self.project.slug,
451+
version=self.version.slug,
452+
msg=exc_value),
453+
exc_info=True)
454454
self.failure = exc_value
455455
return True
456456

@@ -574,10 +574,9 @@ def update_build(self, state=None):
574574
try:
575575
api_v2.build(self.build['id']).put(self.build)
576576
except HttpClientError as e:
577-
log.error(
578-
"Unable to update build: id=%d error=%s",
577+
log.exception(
578+
"Unable to update build: id=%d",
579579
self.build['id'],
580-
e.content,
581580
)
582581
except Exception:
583582
log.exception("Unknown build exception")

readthedocs/oauth/services/base.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def paginate(self, url, **kwargs):
138138
return results
139139
# Catch specific exception related to OAuth
140140
except InvalidClientIdError:
141-
log.error('access_token or refresh_token failed: %s', url)
141+
log.warning('access_token or refresh_token failed: %s', url)
142142
raise Exception('You should reconnect your account')
143143
# Catch exceptions with request or deserializing JSON
144144
except (RequestException, ValueError):
@@ -149,7 +149,10 @@ def paginate(self, url, **kwargs):
149149
except ValueError:
150150
debug_data = resp.content
151151
log.debug(
152-
'paginate failed at %s with response: %s', url, debug_data)
152+
'Paginate failed at %s with response: %s',
153+
url,
154+
debug_data,
155+
)
153156
else:
154157
return []
155158

readthedocs/oauth/services/bitbucket.py

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ def sync_repositories(self):
4545
for repo in repos:
4646
self.create_repository(repo)
4747
except (TypeError, ValueError) as e:
48-
log.error('Error syncing Bitbucket repositories: %s',
49-
str(e), exc_info=True)
48+
log.exception('Error syncing Bitbucket repositories')
5049
raise Exception('Could not sync your Bitbucket repositories, '
5150
'try reconnecting your account')
5251

@@ -80,8 +79,7 @@ def sync_teams(self):
8079
for repo in repos:
8180
self.create_repository(repo, organization=org)
8281
except ValueError as e:
83-
log.error('Error syncing Bitbucket organizations: %s',
84-
str(e), exc_info=True)
82+
log.exception('Error syncing Bitbucket organizations')
8583
raise Exception('Could not sync your Bitbucket team repositories, '
8684
'try reconnecting your account')
8785

@@ -220,19 +218,27 @@ def setup_webhook(self, project):
220218
recv_data = resp.json()
221219
integration.provider_data = recv_data
222220
integration.save()
223-
log.info('Bitbucket webhook creation successful for project: %s',
224-
project)
221+
log.info(
222+
'Bitbucket webhook creation successful for project: %s',
223+
project,
224+
)
225225
return (True, resp)
226226
# Catch exceptions with request or deserializing JSON
227227
except (RequestException, ValueError):
228-
log.error('Bitbucket webhook creation failed for project: %s',
229-
project, exc_info=True)
228+
log.exception(
229+
'Bitbucket webhook creation failed for project: %s',
230+
project,
231+
)
230232
else:
231-
log.error('Bitbucket webhook creation failed for project: %s',
232-
project)
233+
log.exception(
234+
'Bitbucket webhook creation failed for project: %s',
235+
project,
236+
)
233237
try:
234-
log.debug('Bitbucket webhook creation failure response: %s',
235-
resp.json())
238+
log.debug(
239+
'Bitbucket webhook creation failure response: %s',
240+
resp.json(),
241+
)
236242
except ValueError:
237243
pass
238244
return (False, resp)
@@ -263,20 +269,29 @@ def update_webhook(self, project, integration):
263269
recv_data = resp.json()
264270
integration.provider_data = recv_data
265271
integration.save()
266-
log.info('Bitbucket webhook update successful for project: %s',
267-
project)
272+
log.info(
273+
'Bitbucket webhook update successful for project: %s',
274+
project,
275+
)
268276
return (True, resp)
269277
# Catch exceptions with request or deserializing JSON
270278
except (KeyError, RequestException, ValueError):
271-
log.error('Bitbucket webhook update failed for project: %s',
272-
project, exc_info=True)
279+
log.exception(
280+
'Bitbucket webhook update failed for project: %s',
281+
project,
282+
)
273283
else:
274-
log.error('Bitbucket webhook update failed for project: %s',
275-
project)
284+
log.exception(
285+
'Bitbucket webhook update failed for project: %s',
286+
project,
287+
)
276288
# Response data should always be JSON, still try to log if not though
277289
try:
278290
debug_data = resp.json()
279291
except ValueError:
280292
debug_data = resp.content
281-
log.debug('Bitbucket webhook update failure response: %s', debug_data)
293+
log.debug(
294+
'Bitbucket webhook update failure response: %s',
295+
debug_data,
296+
)
282297
return (False, resp)

readthedocs/oauth/services/github.py

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ def sync_repositories(self):
4242
for repo in repos:
4343
self.create_repository(repo)
4444
except (TypeError, ValueError) as e:
45-
log.error('Error syncing GitHub repositories: %s',
46-
str(e), exc_info=True)
45+
log.exception('Error syncing GitHub repositories')
4746
raise Exception('Could not sync your GitHub repositories, '
4847
'try reconnecting your account')
4948

@@ -62,8 +61,7 @@ def sync_organizations(self):
6261
for repo in org_repos:
6362
self.create_repository(repo, organization=org_obj)
6463
except (TypeError, ValueError) as e:
65-
log.error('Error syncing GitHub organizations: %s',
66-
str(e), exc_info=True)
64+
log.exception('Error syncing GitHub organizations')
6765
raise Exception('Could not sync your GitHub organizations, '
6866
'try reconnecting your account')
6967

@@ -211,18 +209,25 @@ def setup_webhook(self, project):
211209
return (True, resp)
212210
# Catch exceptions with request or deserializing JSON
213211
except (RequestException, ValueError):
214-
log.error('GitHub webhook creation failed for project: %s',
215-
project, exc_info=True)
212+
log.exception(
213+
'GitHub webhook creation failed for project: %s',
214+
project,
215+
)
216216
else:
217-
log.error('GitHub webhook creation failed for project: %s',
218-
project)
219-
# Response data should always be JSON, still try to log if not though
217+
log.exception(
218+
'GitHub webhook creation failed for project: %s',
219+
project,
220+
)
221+
# Response data should always be JSON, still try to log if not
222+
# though
220223
try:
221224
debug_data = resp.json()
222225
except ValueError:
223226
debug_data = resp.content
224-
log.debug('GitHub webhook creation failure response: %s',
225-
debug_data)
227+
log.debug(
228+
'GitHub webhook creation failure response: %s',
229+
debug_data,
230+
)
226231
return (False, resp)
227232

228233
def update_webhook(self, project, integration):
@@ -251,22 +256,30 @@ def update_webhook(self, project, integration):
251256
recv_data = resp.json()
252257
integration.provider_data = recv_data
253258
integration.save()
254-
log.info('GitHub webhook creation successful for project: %s',
255-
project)
259+
log.info(
260+
'GitHub webhook creation successful for project: %s',
261+
project,
262+
)
256263
return (True, resp)
257264
# Catch exceptions with request or deserializing JSON
258265
except (RequestException, ValueError):
259-
log.error('GitHub webhook update failed for project: %s',
260-
project, exc_info=True)
266+
log.exception(
267+
'GitHub webhook update failed for project: %s',
268+
project,
269+
)
261270
else:
262-
log.error('GitHub webhook update failed for project: %s',
263-
project)
271+
log.exception(
272+
'GitHub webhook update failed for project: %s',
273+
project,
274+
)
264275
try:
265276
debug_data = resp.json()
266277
except ValueError:
267278
debug_data = resp.content
268-
log.debug('GitHub webhook creation failure response: %s',
269-
debug_data)
279+
log.debug(
280+
'GitHub webhook creation failure response: %s',
281+
debug_data,
282+
)
270283
return (False, resp)
271284

272285
@classmethod

readthedocs/oauth/services/gitlab.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,10 @@ def update_webhook(self, project, integration):
336336
log.exception(
337337
'GitLab webhook update failed for project: %s', project)
338338
else:
339-
log.error('GitLab webhook update failed for project: %s', project)
339+
log.exception(
340+
'GitLab webhook update failed for project: %s',
341+
project,
342+
)
340343
try:
341344
debug_data = resp.json()
342345
except ValueError:

0 commit comments

Comments
 (0)