yangdx
commited on
Commit
·
5fb46b4
1
Parent(s):
fd1695b
feat: add configurable log rotation settings via environment variables
Browse files• Add LOG_DIR env var for log file location
• Add LOG_MAX_BYTES for max log file size
• Add LOG_BACKUP_COUNT for backup count
- .env.example +3 -0
- gunicorn_config.py +11 -6
- lightrag/api/lightrag_server.py +9 -4
.env.example
CHANGED
@@ -23,6 +23,9 @@
|
|
23 |
### Logging level
|
24 |
# LOG_LEVEL=INFO
|
25 |
# VERBOSE=False
|
|
|
|
|
|
|
26 |
|
27 |
### Max async calls for LLM
|
28 |
# MAX_ASYNC=4
|
|
|
23 |
### Logging level
|
24 |
# LOG_LEVEL=INFO
|
25 |
# VERBOSE=False
|
26 |
+
# LOG_DIR=/path/to/log/directory # Log file directory path, defaults to current working directory
|
27 |
+
# LOG_MAX_BYTES=10485760 # Log file max size in bytes, defaults to 10MB
|
28 |
+
# LOG_BACKUP_COUNT=5 # Number of backup files to keep, defaults to 5
|
29 |
|
30 |
### Max async calls for LLM
|
31 |
# MAX_ASYNC=4
|
gunicorn_config.py
CHANGED
@@ -4,8 +4,13 @@ import logging
|
|
4 |
from lightrag.kg.shared_storage import finalize_share_data
|
5 |
from lightrag.api.lightrag_server import LightragPathFilter
|
6 |
|
7 |
-
#
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
# These variables will be set by run_with_gunicorn.py
|
11 |
workers = None
|
@@ -25,8 +30,8 @@ timeout = int(os.getenv("TIMEOUT", 120))
|
|
25 |
keepalive = 5
|
26 |
|
27 |
# Logging configuration
|
28 |
-
errorlog = os.getenv("ERROR_LOG", log_file_path) #
|
29 |
-
accesslog = os.getenv("ACCESS_LOG", log_file_path) #
|
30 |
|
31 |
logconfig_dict = {
|
32 |
"version": 1,
|
@@ -44,8 +49,8 @@ logconfig_dict = {
|
|
44 |
"class": "logging.handlers.RotatingFileHandler",
|
45 |
"formatter": "standard",
|
46 |
"filename": log_file_path,
|
47 |
-
"maxBytes":
|
48 |
-
"backupCount":
|
49 |
"encoding": "utf8",
|
50 |
},
|
51 |
},
|
|
|
4 |
from lightrag.kg.shared_storage import finalize_share_data
|
5 |
from lightrag.api.lightrag_server import LightragPathFilter
|
6 |
|
7 |
+
# Get log directory path from environment variable
|
8 |
+
log_dir = os.getenv("LOG_DIR", os.getcwd())
|
9 |
+
log_file_path = os.path.abspath(os.path.join(log_dir, "lightrag.log"))
|
10 |
+
|
11 |
+
# Get log file max size and backup count from environment variables
|
12 |
+
log_max_bytes = int(os.getenv("LOG_MAX_BYTES", 10485760)) # Default 10MB
|
13 |
+
log_backup_count = int(os.getenv("LOG_BACKUP_COUNT", 5)) # Default 5 backups
|
14 |
|
15 |
# These variables will be set by run_with_gunicorn.py
|
16 |
workers = None
|
|
|
30 |
keepalive = 5
|
31 |
|
32 |
# Logging configuration
|
33 |
+
errorlog = os.getenv("ERROR_LOG", log_file_path) # Default write to lightrag.log
|
34 |
+
accesslog = os.getenv("ACCESS_LOG", log_file_path) # Default write to lightrag.log
|
35 |
|
36 |
logconfig_dict = {
|
37 |
"version": 1,
|
|
|
49 |
"class": "logging.handlers.RotatingFileHandler",
|
50 |
"formatter": "standard",
|
51 |
"filename": log_file_path,
|
52 |
+
"maxBytes": log_max_bytes,
|
53 |
+
"backupCount": log_backup_count,
|
54 |
"encoding": "utf8",
|
55 |
},
|
56 |
},
|
lightrag/api/lightrag_server.py
CHANGED
@@ -430,8 +430,13 @@ def configure_logging():
|
|
430 |
logger.handlers = []
|
431 |
logger.filters = []
|
432 |
|
433 |
-
#
|
434 |
-
|
|
|
|
|
|
|
|
|
|
|
435 |
|
436 |
logging.config.dictConfig(
|
437 |
{
|
@@ -455,8 +460,8 @@ def configure_logging():
|
|
455 |
"formatter": "detailed",
|
456 |
"class": "logging.handlers.RotatingFileHandler",
|
457 |
"filename": log_file_path,
|
458 |
-
"maxBytes":
|
459 |
-
"backupCount":
|
460 |
"encoding": "utf-8",
|
461 |
},
|
462 |
},
|
|
|
430 |
logger.handlers = []
|
431 |
logger.filters = []
|
432 |
|
433 |
+
# Get log directory path from environment variable
|
434 |
+
log_dir = os.getenv("LOG_DIR", os.getcwd())
|
435 |
+
log_file_path = os.path.abspath(os.path.join(log_dir, "lightrag.log"))
|
436 |
+
|
437 |
+
# Get log file max size and backup count from environment variables
|
438 |
+
log_max_bytes = int(os.getenv("LOG_MAX_BYTES", 10485760)) # Default 10MB
|
439 |
+
log_backup_count = int(os.getenv("LOG_BACKUP_COUNT", 5)) # Default 5 backups
|
440 |
|
441 |
logging.config.dictConfig(
|
442 |
{
|
|
|
460 |
"formatter": "detailed",
|
461 |
"class": "logging.handlers.RotatingFileHandler",
|
462 |
"filename": log_file_path,
|
463 |
+
"maxBytes": log_max_bytes,
|
464 |
+
"backupCount": log_backup_count,
|
465 |
"encoding": "utf-8",
|
466 |
},
|
467 |
},
|