Skip to content

Commit

Permalink
Reduce verbosity of cylc clean logging
Browse files Browse the repository at this point in the history
  • Loading branch information
MetRonnie committed Jan 14, 2021
1 parent add6e8b commit dfb28c0
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 16 deletions.
8 changes: 4 additions & 4 deletions cylc/flow/pathutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,15 +219,15 @@ def remove_dir(path):
if os.path.islink(path):
if os.path.exists(path):
target = os.path.realpath(path)
LOG.info(
LOG.debug(
f'Removing symlink target directory: ({path} ->) {target}')
rmtree(target)
LOG.info(f'Removing symlink: {path}')
LOG.debug(f'Removing symlink: {path}')
else:
LOG.info(f'Removing broken symlink: {path}')
LOG.debug(f'Removing broken symlink: {path}')
os.remove(path)
elif not os.path.exists(path):
raise FileNotFoundError(path)
else:
LOG.info(f'Removing directory: {path}')
LOG.debug(f'Removing directory: {path}')
rmtree(path)
9 changes: 9 additions & 0 deletions cylc/flow/scripts/clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
"""

import cylc.flow.flags
from cylc.flow import LOG
from cylc.flow.loggingutil import CylcLogFormatter
from cylc.flow.option_parsers import CylcOptionParser as COP
from cylc.flow.terminal import cli_function
from cylc.flow.suite_files import clean, init_clean
Expand Down Expand Up @@ -63,6 +66,12 @@ def get_option_parser():

@cli_function(get_option_parser)
def main(parser, opts, reg):
if not cylc.flow.flags.debug:
# for readability omit timestamps from logging unless in debug mode
for handler in LOG.handlers:
if isinstance(handler.formatter, CylcLogFormatter):
handler.formatter.configure(timestamp=False)

if opts.local_only:
clean(reg)
else:
Expand Down
25 changes: 14 additions & 11 deletions cylc/flow/suite_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from cylc.flow.exceptions import (
CylcError, PlatformLookupError, SuiteServiceFileError, TaskRemoteMgmtError,
WorkflowFilesError)
import cylc.flow.flags
from cylc.flow.pathutil import (
get_suite_run_dir, make_localhost_symlinks, remove_dir)
from cylc.flow.platforms import (
Expand Down Expand Up @@ -591,15 +592,13 @@ def init_clean(reg, opts):
try:
platform_names = get_platforms_from_db(local_run_dir)
except FileNotFoundError:
LOG.warning(
"The workflow database is missing - will not be able to clean on "
"any remote platforms")
LOG.INFO("No workflow database - will only clean locally")
except SuiteServiceFileError as exc:
raise SuiteServiceFileError(f"Cannot clean - {exc}")

if platform_names and platform_names != {'localhost'}:
remote_clean(reg, platform_names, opts.remote_timeout)
# Lastly, clean on local filesystem:
LOG.info("Cleaning on local filesystem")
clean(reg)


Expand Down Expand Up @@ -672,6 +671,8 @@ def remote_clean(reg, platform_names, timeout):
if target == 'localhost':
continue
shuffle(platforms)
LOG.info(
f"Cleaning on install target: {platforms[0]['install target']}")
# Issue ssh command:
pool.append(
(_remote_clean_cmd(reg, platforms[0], timeout), target, platforms)
Expand All @@ -686,23 +687,23 @@ def remote_clean(reg, platform_names, timeout):
pool.remove((proc, target, platforms))
out, err = (f.decode() for f in proc.communicate())
if out:
LOG.info(out)
if err:
LOG.warning(err)
LOG.debug(out)
if ret_code:
# Try again using the next platform for this install target:
this_platform = platforms.pop(0)
exc = TaskRemoteMgmtError(
TaskRemoteMgmtError.MSG_TIDY, this_platform['name'],
" ".join(proc.args), ret_code, out, err)
LOG.error(exc)
LOG.debug(exc)
if platforms:
pool.append(
(_remote_clean_cmd(reg, platforms[0], timeout),
target, platforms)
)
else: # Exhausted list of platforms
failed_targets.append(target)
elif err:
LOG.debug(err)
time.sleep(0.2)
if failed_targets:
raise CylcError(
Expand All @@ -720,10 +721,12 @@ def _remote_clean_cmd(reg, platform, timeout):
workflow.
timeout (str): Number of seconds to wait before cancelling the command.
"""
LOG.info(
LOG.debug(
f'Cleaning on install target: {platform["install target"]} '
f'(platform: {platform["name"]})')
f'(using platform: {platform["name"]})')
cmd = ['clean', '--local-only', reg]
if cylc.flow.flags.debug:
cmd.append('--debug')
cmd = construct_ssh_cmd(cmd, platform, timeout=timeout)
LOG.debug(" ".join(cmd))
return Popen(cmd, stdin=DEVNULL, stdout=PIPE, stderr=PIPE)
Expand Down Expand Up @@ -753,7 +756,7 @@ def _remove_empty_reg_parents(reg, path):
continue
try:
parent.rmdir()
LOG.info(f'Removing directory: {parent}')
LOG.debug(f'Removing directory: {parent}')
except OSError:
break

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_suite_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ def test_remote_clean(install_targets_map, failed_platforms,
(Exception, str) giving an exception that is expected to be raised.
"""
# ----- Setup -----
caplog.set_level(logging.ERROR, CYLC_LOG)
caplog.set_level(logging.DEBUG, CYLC_LOG)
monkeypatch.setattr(
'cylc.flow.suite_files.get_install_target_to_platforms_map',
lambda x: install_targets_map)
Expand Down

0 comments on commit dfb28c0

Please sign in to comment.