From e5e69efca63e041ed86009f22f23714d43b9958d Mon Sep 17 00:00:00 2001 From: Lorenzo Gaifas Date: Wed, 30 Aug 2023 17:17:39 +0200 Subject: [PATCH] add logging --- README.md | 2 ++ src/waretomo/main.py | 20 +++++++++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 749e61b..b7e5e9c 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,8 @@ pip install waretomo waretomo -h ``` +Every time you run waretomo, a log will be appended to an `waretomo.log` file in the output directory. + # Walkthrough Here's a short summary of how I recommend using this script: diff --git a/src/waretomo/main.py b/src/waretomo/main.py index 1929bff..32504a0 100644 --- a/src/waretomo/main.py +++ b/src/waretomo/main.py @@ -183,6 +183,8 @@ def cli( Assumes the default Warp directory structure with generated imod stacks. """ + import sys + from datetime import datetime from inspect import cleandoc from pathlib import Path @@ -294,10 +296,8 @@ def cli( f'{nl}{" " * 12}- {k}: {v}' for k, v in topaz_kwargs.items() ) - print( - Panel( - cleandoc( - f""" + summary = cleandoc( + f""" [bold]Warp directory[/bold]: {warp_dir} [bold]Mdoc directory[/bold]: {mdoc_dir} [bold]Tilt series - NOT READY[/bold]: {not_ready_log} @@ -307,10 +307,16 @@ def cli( [bold]Run options[/bold]: {opts_log} [bold]AreTomo options[/bold]: {aretomo_opts_log} [bold]Topaz options[/bold]: {topaz_log} - """ - ) - ) + """ ) + print(Panel(summary)) + + if not dry_run: + with open(output_dir / "waretomo.log", "a") as f: + print("=" * 80, file=f) + print(datetime.now().strftime("%d/%m/%Y %H:%M:%S"), file=f) + print(f'Command: {" ".join(sys.argv)}', file=f) + print(summary, "\n", file=f) if steps["fix"]: from ._fix import fix_batch