Skip to content

Commit

Permalink
use the harmonized logging setup
Browse files Browse the repository at this point in the history
  • Loading branch information
leoschwarz committed Aug 5, 2024
1 parent 06dc58b commit 3423214
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
12 changes: 12 additions & 0 deletions bfabric/cli_formatting.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import sys

from loguru import logger
from rich.highlighter import RegexHighlighter
from rich.theme import Theme

Expand All @@ -10,3 +13,12 @@ class HostnameHighlighter(RegexHighlighter):


DEFAULT_THEME = Theme({"bfabric.hostname": "bold red"})


def setup_script_logging(debug: bool = False) -> None:
"""Sets up the logging for the command line scripts."""
logger.remove()
if not debug:
logger.add(sys.stderr, filter="bfabric", level="INFO", format="{level} {message}")
else:
logger.add(sys.stderr, filter="bfabric", level="DEBUG")
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
from datetime import datetime, timedelta
from typing import Any

from loguru import logger
from rich.console import Console
from rich.table import Column, Table

from bfabric import Bfabric, BfabricClientConfig
from bfabric.cli_formatting import setup_script_logging


def render_output(workunits_by_status: dict[str, list[dict[str, Any]]], config: BfabricClientConfig) -> None:
Expand Down Expand Up @@ -60,6 +62,12 @@ def render_output(workunits_by_status: dict[str, list[dict[str, Any]]], config:
def list_not_available_proteomics_workunits(date_cutoff: datetime) -> None:
"""Lists proteomics work units that are not available on bfabric."""
client = Bfabric.from_config()
console = Console()
with console.capture() as capture:
console.print(
f"listing not available proteomics work units created after {date_cutoff}", style="bright_yellow", end=""
)
logger.info(capture.get())

workunits_by_status = {}
for status in ["Pending", "Processing", "Failed"]:
Expand All @@ -73,6 +81,7 @@ def list_not_available_proteomics_workunits(date_cutoff: datetime) -> None:

def main() -> None:
"""Parses the command line arguments and calls `list_not_available_proteomics_workunits`."""
setup_script_logging()
parser = ArgumentParser(description="Lists proteomics work units that are not available on bfabric.")
parser.add_argument("--max-age", type=int, help="Max age of work units in days", default=14)
args = parser.parse_args()
Expand Down

0 comments on commit 3423214

Please sign in to comment.