mirror of
https://github.com/HKUDS/LightRAG.git
synced 2025-06-26 22:00:19 +00:00
feat: add configurable log rotation settings via environment variables
• 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
This commit is contained in:
parent
731d820bcc
commit
aac1bdd9e6
@ -23,6 +23,9 @@
|
|||||||
### Logging level
|
### Logging level
|
||||||
# LOG_LEVEL=INFO
|
# LOG_LEVEL=INFO
|
||||||
# VERBOSE=False
|
# VERBOSE=False
|
||||||
|
# LOG_DIR=/path/to/log/directory # Log file directory path, defaults to current working directory
|
||||||
|
# LOG_MAX_BYTES=10485760 # Log file max size in bytes, defaults to 10MB
|
||||||
|
# LOG_BACKUP_COUNT=5 # Number of backup files to keep, defaults to 5
|
||||||
|
|
||||||
### Max async calls for LLM
|
### Max async calls for LLM
|
||||||
# MAX_ASYNC=4
|
# MAX_ASYNC=4
|
||||||
|
@ -4,8 +4,13 @@ import logging
|
|||||||
from lightrag.kg.shared_storage import finalize_share_data
|
from lightrag.kg.shared_storage import finalize_share_data
|
||||||
from lightrag.api.lightrag_server import LightragPathFilter
|
from lightrag.api.lightrag_server import LightragPathFilter
|
||||||
|
|
||||||
# 获取日志文件路径
|
# Get log directory path from environment variable
|
||||||
log_file_path = os.path.abspath(os.path.join(os.getcwd(), "lightrag.log"))
|
log_dir = os.getenv("LOG_DIR", os.getcwd())
|
||||||
|
log_file_path = os.path.abspath(os.path.join(log_dir, "lightrag.log"))
|
||||||
|
|
||||||
|
# Get log file max size and backup count from environment variables
|
||||||
|
log_max_bytes = int(os.getenv("LOG_MAX_BYTES", 10485760)) # Default 10MB
|
||||||
|
log_backup_count = int(os.getenv("LOG_BACKUP_COUNT", 5)) # Default 5 backups
|
||||||
|
|
||||||
# These variables will be set by run_with_gunicorn.py
|
# These variables will be set by run_with_gunicorn.py
|
||||||
workers = None
|
workers = None
|
||||||
@ -25,8 +30,8 @@ timeout = int(os.getenv("TIMEOUT", 120))
|
|||||||
keepalive = 5
|
keepalive = 5
|
||||||
|
|
||||||
# Logging configuration
|
# Logging configuration
|
||||||
errorlog = os.getenv("ERROR_LOG", log_file_path) # 默认写入到 lightrag.log
|
errorlog = os.getenv("ERROR_LOG", log_file_path) # Default write to lightrag.log
|
||||||
accesslog = os.getenv("ACCESS_LOG", log_file_path) # 默认写入到 lightrag.log
|
accesslog = os.getenv("ACCESS_LOG", log_file_path) # Default write to lightrag.log
|
||||||
|
|
||||||
logconfig_dict = {
|
logconfig_dict = {
|
||||||
"version": 1,
|
"version": 1,
|
||||||
@ -44,8 +49,8 @@ logconfig_dict = {
|
|||||||
"class": "logging.handlers.RotatingFileHandler",
|
"class": "logging.handlers.RotatingFileHandler",
|
||||||
"formatter": "standard",
|
"formatter": "standard",
|
||||||
"filename": log_file_path,
|
"filename": log_file_path,
|
||||||
"maxBytes": 10485760, # 10MB
|
"maxBytes": log_max_bytes,
|
||||||
"backupCount": 5,
|
"backupCount": log_backup_count,
|
||||||
"encoding": "utf8",
|
"encoding": "utf8",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -430,8 +430,13 @@ def configure_logging():
|
|||||||
logger.handlers = []
|
logger.handlers = []
|
||||||
logger.filters = []
|
logger.filters = []
|
||||||
|
|
||||||
# Configure basic logging
|
# Get log directory path from environment variable
|
||||||
log_file_path = os.path.abspath(os.path.join(os.getcwd(), "lightrag.log"))
|
log_dir = os.getenv("LOG_DIR", os.getcwd())
|
||||||
|
log_file_path = os.path.abspath(os.path.join(log_dir, "lightrag.log"))
|
||||||
|
|
||||||
|
# Get log file max size and backup count from environment variables
|
||||||
|
log_max_bytes = int(os.getenv("LOG_MAX_BYTES", 10485760)) # Default 10MB
|
||||||
|
log_backup_count = int(os.getenv("LOG_BACKUP_COUNT", 5)) # Default 5 backups
|
||||||
|
|
||||||
logging.config.dictConfig(
|
logging.config.dictConfig(
|
||||||
{
|
{
|
||||||
@ -455,8 +460,8 @@ def configure_logging():
|
|||||||
"formatter": "detailed",
|
"formatter": "detailed",
|
||||||
"class": "logging.handlers.RotatingFileHandler",
|
"class": "logging.handlers.RotatingFileHandler",
|
||||||
"filename": log_file_path,
|
"filename": log_file_path,
|
||||||
"maxBytes": 10 * 1024 * 1024, # 10MB
|
"maxBytes": log_max_bytes,
|
||||||
"backupCount": 5,
|
"backupCount": log_backup_count,
|
||||||
"encoding": "utf-8",
|
"encoding": "utf-8",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user