Skip to content
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

Clean up logging #4665

Merged
merged 2 commits into from Oct 2, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 5 additions & 18 deletions readthedocs/doc_builder/environments.py
Expand Up @@ -319,13 +319,6 @@ def __init__(self, project, environment=None):
def record_command(self, command):
pass

def _log_warning(self, msg):
log.warning(LOG_TEMPLATE.format(
project=self.project.slug,
version='latest',
msg=msg,
))

def run(self, *cmd, **kwargs):
"""Shortcut to run command from environment."""
return self.run_command_class(cls=self.command_class, cmd=cmd, **kwargs)
Expand Down Expand Up @@ -388,7 +381,11 @@ def run_command_class(
msg += u':\n{out}'.format(out=build_cmd.output)

if warn_only:
self._log_warning(msg)
log.warning(LOG_TEMPLATE.format(
project=self.project.slug,
version='latest',
msg=msg,
))
else:
raise BuildEnvironmentWarning(msg)
return build_cmd
Expand Down Expand Up @@ -517,16 +514,6 @@ def handle_exception(self, exc_type, exc_value, _):
def record_command(self, command):
command.save()

def _log_warning(self, msg):
# :'(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Goodbye sad face :(

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

He'll still be in our git history. :')

log.warning(
LOG_TEMPLATE.format(
project=self.project.slug,
version=self.version.slug,
msg=msg,
)
)

def run(self, *cmd, **kwargs):
kwargs.update({
'build_env': self,
Expand Down
24 changes: 15 additions & 9 deletions readthedocs/doc_builder/python_environments.py
Expand Up @@ -39,26 +39,28 @@ def __init__(self, version, build_env, config=None):
# Compute here, since it's used a lot
self.checkout_path = self.project.checkout_path(self.version.slug)

def _log(self, msg):
log.info(LOG_TEMPLATE
.format(project=self.project.slug,
version=self.version.slug,
msg=msg))

def delete_existing_build_dir(self):
# Handle deleting old build dir
build_dir = os.path.join(
self.venv_path(),
'build')
if os.path.exists(build_dir):
self._log('Removing existing build directory')
log.info(LOG_TEMPLATE.format(
project=self.project.slug,
version=self.version.slug,
msg='Removing existing build directory',
))
shutil.rmtree(build_dir)

def delete_existing_venv_dir(self):
venv_dir = self.venv_path()
# Handle deleting old venv dir
if os.path.exists(venv_dir):
self._log('Removing existing venv directory')
log.info(LOG_TEMPLATE.format(
project=self.project.slug,
version=self.version.slug,
msg='Removing existing venv directory',
))
shutil.rmtree(venv_dir)

def install_package(self):
Expand Down Expand Up @@ -325,7 +327,11 @@ def setup_base(self):

if os.path.exists(version_path):
# Re-create conda directory each time to keep fresh state
self._log('Removing existing conda directory')
log.info(LOG_TEMPLATE.format(
project=self.project.slug,
version=self.version.slug,
msg='Removing existing conda directory',
))
shutil.rmtree(version_path)
self.build_env.run(
'conda',
Expand Down
49 changes: 26 additions & 23 deletions readthedocs/projects/tasks.py
Expand Up @@ -110,12 +110,15 @@ def sync_repo(self):
# Get the actual code on disk
try:
before_vcs.send(sender=self.version)
self._log(
'Checking out version {slug}: {identifier}'.format(
slug=self.version.slug,
identifier=self.version.identifier,
),
msg = 'Checking out version {slug}: {identifier}'.format(
slug=self.version.slug,
identifier=self.version.identifier,
)
log.info(LOG_TEMPLATE.format(
project=self.project.slug,
version=self.version.slug,
msg=msg,
))
version_repo = self.project.vcs_repo(
self.version.slug,
# When called from ``SyncRepositoryTask.run`` we don't have
Expand Down Expand Up @@ -176,15 +179,6 @@ def validate_duplicate_reserved_versions(self, data):
RepositoryError.DUPLICATED_RESERVED_VERSIONS
)

# TODO this is duplicated in the classes below, and this should be
# refactored out anyways, as calling from the method removes the original
# caller from logging.
def _log(self, msg):
log.info(LOG_TEMPLATE
.format(project=self.project.slug,
version=self.version.slug,
msg=msg))


# TODO SyncRepositoryTask should be refactored into a standard celery task,
# there is no more need to have this be a separate class
Expand Down Expand Up @@ -292,12 +286,6 @@ def __init__(self, build_env=None, python_env=None, config=None,
self.task = task
self.setup_env = None

def _log(self, msg):
log.info(LOG_TEMPLATE
.format(project=self.project.slug,
version=self.version.slug,
msg=msg))

# pylint: disable=arguments-differ
def run(self, pk, version_pk=None, build_pk=None, record=True,
docker=None, search=True, force=False, localmedia=True, **__):
Expand Down Expand Up @@ -428,7 +416,14 @@ def run_setup(self, record=True):
))

if self.setup_env.failure or self.config is None:
self._log('Failing build because of setup failure: %s' % self.setup_env.failure)
msg = 'Failing build because of setup failure: {}'.format(
self.setup_env.failure
)
log.info(LOG_TEMPLATE.format(
project=self.project.slug,
version=self.version.slug,
msg=msg,
))

# Send notification to users only if the build didn't fail because of
# LockTimeout: this exception occurs when a build is triggered before the previous
Expand Down Expand Up @@ -476,7 +471,11 @@ def run_build(self, docker, record):

python_env_cls = Virtualenv
if self.config.conda is not None:
self._log('Using conda')
log.info(LOG_TEMPLATE.format(
project=self.project.slug,
version=self.version.slug,
msg='Using conda',
))
python_env_cls = Conda
self.python_env = python_env_cls(
version=self.version,
Expand Down Expand Up @@ -544,7 +543,11 @@ def setup_vcs(self):
"""
self.setup_env.update_build(state=BUILD_STATE_CLONING)

self._log(msg='Updating docs from VCS')
log.info(LOG_TEMPLATE.format(
project=self.project.slug,
version=self.version.slug,
msg='Updating docs from VCS',
))
self.sync_repo()
commit = self.project.vcs_repo(self.version.slug).commit
if commit:
Expand Down