-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor to replace old logging to avoid mangling #3677
Conversation
readthedocs/core/symlink.py
Outdated
def _log(self, msg, level='info'): | ||
logger = getattr(log, level) | ||
logger(constants.LOG_TEMPLATE | ||
def _log(self, msg): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the original issue means to remove this method and do each call directly to log.info.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, apologies but I am confused about this. The issue's primary concern seems to be an external logger mangling with the built-in one. This fixes this.
Inline-ing means, it would look like:
log.info(constants.LOG_TEMPLATE.format(project=self.project.slug, version='',msg=msg))
Why not use a helper method instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When we log with a helper method, all of our logging messages reference the file/lineno location of the _log
method, not where we actually called the log method from.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@agjohnson @stsewd Ah I see, I have made the necessary changes.
I have not changed other files, because I want to make sure this is the pattern to cover for other files too. Let me know, thanks. |
readthedocs/core/symlink.py
Outdated
@@ -152,7 +146,9 @@ def symlink_cnames(self, domain=None): | |||
else: | |||
domains = Domain.objects.filter(project=self.project) | |||
for dom in domains: | |||
self._log(u"Symlinking CNAME: {0} -> {1}".format(dom.domain, self.project.slug)) | |||
log_msg = u"Symlinking CNAME: {0} -> {1}".format(dom.domain, self.project.slug) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use single quotes '
on literal strings, also we could get rid of the u
by importing the unicode_literals
or run isort
to do it automatically :)
Travis is falling because of the linter, you can run the linter locally withtox -e py27-lint
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And please, could you don't touch the readthedocs/doc_builder/environments.py
file? I'm taking care of the logging issue while refactoring on #3687, thanks!
|
Ping |
@SanketDG here you can see the lint error on travis https://travis-ci.org/rtfd/readthedocs.org/jobs/346909685#L813. The continuation line is bad indented. |
All tests have passed now. Need further review. |
@@ -164,7 +160,9 @@ def symlink_cnames(self, domain=None): | |||
|
|||
def remove_symlink_cname(self, domain): | |||
"""Remove CNAME symlink.""" | |||
self._log(u"Removing symlink for CNAME {0}".format(domain.domain)) | |||
log_msg = "Removing symlink for CNAME {0}".format(domain.domain) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use single quotes on all new code to keeping consistency.
Looks good, thanks! |
Fixes #3665