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

[FIX] Show logs in re-runs #637

Merged
merged 6 commits into from
Jan 4, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions tedana/workflows/tedana.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,18 +355,17 @@ def tedana_workflow(data, tes, out_dir='.', mask=None,
# Removing handlers after basicConfig doesn't work, so we use filters
# for the relevant handlers themselves.
log_handler.addFilter(ContextFilter())
logging.root.addHandler(log_handler)
sh = logging.StreamHandler()
sh.addFilter(ContextFilter())
logging.root.addHandler(sh)

if quiet:
logging.basicConfig(level=logging.WARNING,
handlers=[log_handler, sh])
logging.root.setLevel(logging.WARNING)
elif debug:
logging.basicConfig(level=logging.DEBUG,
handlers=[log_handler, sh])
logging.root.setLevel(logging.DEBUG)
else:
logging.basicConfig(level=logging.INFO,
handlers=[log_handler, sh])
logging.root.setLevel(logging.INFO)

# Loggers for report and references
rep_handler = logging.FileHandler(repname)
Expand All @@ -375,7 +374,7 @@ def tedana_workflow(data, tes, out_dir='.', mask=None,
ref_handler.setFormatter(text_formatter)
RepLGR.setLevel(logging.INFO)
RepLGR.addHandler(rep_handler)
RepLGR.setLevel(logging.INFO)
RefLGR.setLevel(logging.INFO)
Comment on lines -378 to +377
Copy link
Member

Choose a reason for hiding this comment

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

Nice catch!

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hm, maybe we should make those variables more distinct, or else we'll probably just do this again later.

RefLGR.addHandler(ref_handler)

LGR.info('Using output directory: {}'.format(out_dir))
Expand Down Expand Up @@ -665,10 +664,16 @@ def tedana_workflow(data, tes, out_dir='.', mask=None,
report += '\n\nReferences:\n\n' + references
with open(repname, 'w') as fo:
fo.write(report)
os.remove(refname)

for handler in logging.root.handlers[:]:
logging.root.removeHandler(handler)
log_handler.close()
logging.root.removeHandler(log_handler)
sh.close()
logging.root.removeHandler(sh)
for local_logger in (RefLGR, RepLGR):
for handler in local_logger.handlers[:]:
handler.close()
local_logger.removeHandler(handler)
os.remove(refname)


def _main(argv=None):
Expand Down