From 49932539daf9fbcd0adc0404ee399addc72f7939 Mon Sep 17 00:00:00 2001 From: Nick Pegg Date: Sat, 3 Aug 2024 08:51:09 -0700 Subject: [PATCH] Add RichHandler for logging --- photoalbum/cli.py | 14 +++++++++++--- photoalbum/generate.py | 4 +++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/photoalbum/cli.py b/photoalbum/cli.py index 6ecb563..faf16b2 100644 --- a/photoalbum/cli.py +++ b/photoalbum/cli.py @@ -4,6 +4,7 @@ from pathlib import Path from photoalbum.config import DEFAULT_CONFIG_PATH, Config from photoalbum.generate import generate +from rich.logging import RichHandler logger = logging.getLogger("photoalbum.cli") @@ -91,10 +92,17 @@ def parse_args() -> Namespace: return parser.parse_args() -def setup_logging(level: str) -> None: +def setup_logging(level_str: str) -> None: levels = logging.getLevelNamesMapping() - # TODO: Set up a better formatter with date/time and stuff - logging.basicConfig(level=levels[level.upper()]) + level = levels[level_str.upper()] + logging.basicConfig( + level=level, + handlers=[RichHandler(rich_tracebacks=True)], + ) + # Override PIL logging because debug is really noisy + if level <= logging.DEBUG: + logging.getLogger("PIL").setLevel(logging.INFO) + if __name__ == "__main__": diff --git a/photoalbum/generate.py b/photoalbum/generate.py index 7c1c613..bedec13 100644 --- a/photoalbum/generate.py +++ b/photoalbum/generate.py @@ -14,7 +14,7 @@ def generate(config: Config, album_path: Path) -> None: Main generation function """ skel_files_created, skel_files = maybe_create_skeleton(config, album_path) - # generate_thumbnails(config, album_path) + generate_thumbnails(config, album_path) # generate_html(config, album_path) if skel_files_created: @@ -82,11 +82,13 @@ def generate_thumbnails(config: Config, path: Path) -> None: thumb_img.thumbnail(config.thumbnail_size) thumb_filename = file_path.stem + ".thumb" + file_path.suffix thumb_img.save(slides_path / thumb_filename) + logger.info(f"Generated thumbnail size {parent_path / filename} -> {thumb_filename}") screen_img = orig_img.copy() screen_img.thumbnail(config.view_size) screen_filename = file_path.stem + ".screen" + file_path.suffix screen_img.save(slides_path / screen_filename) + logger.info(f"Generated screen size {parent_path / filename} -> {screen_filename}") def generate_html(config: Config, path: Path) -> None: