From 6ae313c6bf1b16a915b473b484c32b523a7972d2 Mon Sep 17 00:00:00 2001 From: Leon Derczynski Date: Fri, 2 Aug 2024 01:43:12 +0200 Subject: [PATCH] print logfile path when invoked from CLI (#811) * print logfile path when invoked from CLI * only print logging file path if there's a run --- garak/cli.py | 5 ++++- garak/command.py | 9 ++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/garak/cli.py b/garak/cli.py index 5321e7119..c6df1af70 100644 --- a/garak/cli.py +++ b/garak/cli.py @@ -26,7 +26,7 @@ def main(arguments=None) -> None: import re from colorama import Fore, Style - command.start_logging() + log_filename = command.start_logging() _config.load_base_config() print( @@ -421,6 +421,9 @@ def main(arguments=None) -> None: # model is specified, we're doing something elif _config.plugins.model_type: + + print(f"📜 logging to {log_filename}") + conf_root = _config.plugins.generators for part in _config.plugins.model_type.split("."): if not part in conf_root: diff --git a/garak/command.py b/garak/command.py index dc45d9242..ec61b3ba0 100644 --- a/garak/command.py +++ b/garak/command.py @@ -10,12 +10,13 @@ def start_logging(): from garak import _config + log_filename = _config.transient.data_dir / "garak.log" + logging.basicConfig( - filename=_config.transient.data_dir / "garak.log", + filename=log_filename, level=logging.DEBUG, format="%(asctime)s %(levelname)s %(message)s", ) - # garaklogger = logging.FileHandler("garak.log", encoding="utf-8") # garakformatter = logging.Formatter("%(asctime)s %(levelname)s %(message)s") # garaklogger.setFormatter(garakformatter) @@ -28,6 +29,8 @@ def start_logging(): # logging.root = rootlogger logging.info("invoked") + return log_filename + def start_run(): import logging @@ -53,7 +56,7 @@ def start_run(): report_path.mkdir(mode=0o740, parents=True, exist_ok=True) except PermissionError as e: raise PermissionError( - f"Can't create logging directory {report_path}, quitting" + f"Can't create reporting directory {report_path}, quitting" ) from e filename = f"garak.{_config.transient.run_id}.report.jsonl"