Skip to content

Commit 21eafc1

Browse files
authored
Custom log file placement (#669)
* made log util use env vars for custom log file placement * cleaned up log file config a bit It doesn't seem necessary to split the configuration of log file into log path and log name, but cleaner to just combine them.
1 parent c2f1c51 commit 21eafc1

3 files changed

Lines changed: 7 additions & 8 deletions

File tree

.env.example

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
# LOG_LEVEL=
2-
# LOG_PATH=
3-
# LOG_NAME=
1+
LOG_LEVEL=INFO
2+
LOG_FILE="logs/vectordb_bench.log"
43
# TIMEZONE=
54

65
# NUM_PER_BATCH=

vectordb_bench/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class config:
1414
AWS_S3_URL = "assets.zilliz.com/benchmark/"
1515

1616
LOG_LEVEL = env.str("LOG_LEVEL", "INFO")
17+
LOG_FILE = env.str("LOG_FILE", "logs/vectordb_bench.log")
1718

1819
DEFAULT_DATASET_URL = env.str("DEFAULT_DATASET_URL", AWS_S3_URL)
1920
DATASET_SOURCE = env.str("DATASET_SOURCE", "S3") # Options "S3" or "AliyunOSS"
@@ -79,4 +80,4 @@ def display(self) -> str:
7980
]
8081

8182

82-
log_util.init(config.LOG_LEVEL)
83+
log_util.init(config.LOG_LEVEL, pathlib.Path(config.LOG_FILE))

vectordb_bench/log_util.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
from pathlib import Path
44

55

6-
def init(log_level: str):
6+
def init(log_level: str, log_file: Path):
77
# Create logs directory if it doesn't exist
8-
log_dir = Path("logs")
9-
log_dir.mkdir(exist_ok=True)
8+
log_file.parent.mkdir(exist_ok=True, parents=True)
109

1110
log_config = {
1211
"version": 1,
@@ -32,7 +31,7 @@ def init(log_level: str):
3231
"file": {
3332
"class": "logging.handlers.RotatingFileHandler",
3433
"formatter": "default",
35-
"filename": "logs/vectordb_bench.log",
34+
"filename": log_file,
3635
"maxBytes": 10485760, # 10MB
3736
"backupCount": 5,
3837
"encoding": "utf8",

0 commit comments

Comments
 (0)