diff --git a/.env.example b/.env.example index 618cac556..e495ea999 100644 --- a/.env.example +++ b/.env.example @@ -1,6 +1,5 @@ -# LOG_LEVEL= -# LOG_PATH= -# LOG_NAME= +LOG_LEVEL=INFO +LOG_FILE="logs/vectordb_bench.log" # TIMEZONE= # NUM_PER_BATCH= diff --git a/vectordb_bench/__init__.py b/vectordb_bench/__init__.py index cec641fbd..07f77bb02 100644 --- a/vectordb_bench/__init__.py +++ b/vectordb_bench/__init__.py @@ -14,6 +14,7 @@ class config: AWS_S3_URL = "assets.zilliz.com/benchmark/" LOG_LEVEL = env.str("LOG_LEVEL", "INFO") + LOG_FILE = env.str("LOG_FILE", "logs/vectordb_bench.log") DEFAULT_DATASET_URL = env.str("DEFAULT_DATASET_URL", AWS_S3_URL) DATASET_SOURCE = env.str("DATASET_SOURCE", "S3") # Options "S3" or "AliyunOSS" @@ -79,4 +80,4 @@ def display(self) -> str: ] -log_util.init(config.LOG_LEVEL) +log_util.init(config.LOG_LEVEL, pathlib.Path(config.LOG_FILE)) diff --git a/vectordb_bench/log_util.py b/vectordb_bench/log_util.py index 6ca6ccabf..69dae293d 100644 --- a/vectordb_bench/log_util.py +++ b/vectordb_bench/log_util.py @@ -3,10 +3,9 @@ from pathlib import Path -def init(log_level: str): +def init(log_level: str, log_file: Path): # Create logs directory if it doesn't exist - log_dir = Path("logs") - log_dir.mkdir(exist_ok=True) + log_file.parent.mkdir(exist_ok=True, parents=True) log_config = { "version": 1, @@ -32,7 +31,7 @@ def init(log_level: str): "file": { "class": "logging.handlers.RotatingFileHandler", "formatter": "default", - "filename": "logs/vectordb_bench.log", + "filename": log_file, "maxBytes": 10485760, # 10MB "backupCount": 5, "encoding": "utf8",