Skip to content

Commit

Permalink
print logfile path when invoked from CLI (#811)
Browse files Browse the repository at this point in the history
* print logfile path when invoked from CLI

* only print logging file path if there's a run
  • Loading branch information
leondz authored Aug 1, 2024
1 parent 85ec7bf commit 6ae313c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
5 changes: 4 additions & 1 deletion garak/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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:
Expand Down
9 changes: 6 additions & 3 deletions garak/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -28,6 +29,8 @@ def start_logging():
# logging.root = rootlogger
logging.info("invoked")

return log_filename


def start_run():
import logging
Expand All @@ -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"
Expand Down

0 comments on commit 6ae313c

Please sign in to comment.