From 776fd7abd3a7b4e34e22cc81a20c509190604c5f Mon Sep 17 00:00:00 2001 From: NetroScript Date: Sun, 29 Oct 2023 22:43:31 +0100 Subject: [PATCH] Remove loguru in favor of simple logging module See #1133 --- scripts/ingest_folder.py | 35 ++++++++++++----------------------- 1 file changed, 12 insertions(+), 23 deletions(-) diff --git a/scripts/ingest_folder.py b/scripts/ingest_folder.py index fb8991795..b59d70e8c 100644 --- a/scripts/ingest_folder.py +++ b/scripts/ingest_folder.py @@ -1,13 +1,13 @@ import argparse -import sys +import logging from pathlib import Path -from loguru import logger - from private_gpt.di import root_injector from private_gpt.server.ingest.ingest_service import IngestService from private_gpt.server.ingest.ingest_watcher import IngestWatcher +logger = logging.getLogger(__name__) + ingest_service = root_injector.get(IngestService) parser = argparse.ArgumentParser(prog="ingest_folder.py") @@ -26,28 +26,17 @@ ) args = parser.parse_args() -# Set up loguru logging -# Remove pre-configured logging handler -logger.remove(0) -# For console colorized output without line and function info: -logger.add( - sys.stdout, - level="INFO", - colorize=True, - format=( - "{time:YYYY-MM-DD HH:mm:ss.SSS} | " - "{level: <8} | " - "{message}" - ), -) -# For file output, using a clear and timestamped format: +# Set up logging to a file if a path is provided if args.log_file: - logger.add( - args.log_file, - rotation="10 MB", - level="INFO", - format="[{time:YYYY-MM-DD HH:mm:ss}] [{level}] {message}", + file_handler = logging.FileHandler(args.log_file, mode="a") + file_handler.setFormatter( + logging.Formatter( + "[%(asctime)s.%(msecs)03d] [%(levelname)s] %(message)s", + datefmt="%Y-%m-%d %H:%M:%S", + ) ) + logger.addHandler(file_handler) + total_documents = 0 current_document_count = 0