Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

feat: support user-defined configuration of log file size and retention count (#9610)

zhuhaoc9dfe1ad92cc
diff --git a/api/.env.example b/api/.env.example
index 32cf4293f7a..960d8b18797 100644
--- a/api/.env.example
+++ b/api/.env.example
@@ -309,6 +309,10 @@ RESPECT_XFORWARD_HEADERS_ENABLED=false
# Log file path
LOG_FILE=
+# Log file max size, the unit is MB
+LOG_FILE_MAX_SIZE=20
+# Log file max backup count
+LOG_FILE_BACKUP_COUNT=5
# Indexing configuration
INDEXING_MAX_SEGMENTATION_TOKENS_LENGTH=1000
diff --git a/api/configs/feature/__init__.py b/api/configs/feature/__init__.py
index 8f873569347..4d6c9aedc11 100644
--- a/api/configs/feature/__init__.py
+++ b/api/configs/feature/__init__.py
@@ -319,6 +319,16 @@ class LoggingConfig(BaseSettings):
default=None,
)
+ LOG_FILE_MAX_SIZE: PositiveInt = Field(
+ description="Maximum file size for file rotation retention, the unit is megabytes (MB)",
+ default=20,
+ )
+
+ LOG_FILE_BACKUP_COUNT: PositiveInt = Field(
+ description="Maximum file backup count file rotation retention",
+ default=5,
+ )
+
LOG_FORMAT: str = Field(
description="Format string for log messages",
default="%(asctime)s.%(msecs)03d %(levelname)s [%(threadName)s] [%(filename)s:%(lineno)d] - %(message)s",
diff --git a/api/extensions/ext_logging.py b/api/extensions/ext_logging.py
index 9e1a241b672..56b1d6bd28b 100644
--- a/api/extensions/ext_logging.py
+++ b/api/extensions/ext_logging.py
@@ -17,8 +17,8 @@ def init_app(app: Flask):
log_handlers = [
RotatingFileHandler(
filename=log_file,
- maxBytes=1024 * 1024 * 1024,
- backupCount=5,
+ maxBytes=dify_config.LOG_FILE_MAX_SIZE * 1024 * 1024,
+ backupCount=dify_config.LOG_FILE_BACKUP_COUNT,
),
logging.StreamHandler(sys.stdout),
]
diff --git a/docker/.env.example b/docker/.env.example
index f022a451cf1..dbdc943b060 100644
--- a/docker/.env.example
+++ b/docker/.env.example
@@ -48,6 +48,12 @@ FILES_URL=
# The log level for the application.
# Supported values are `DEBUG`, `INFO`, `WARNING`, `ERROR`, `CRITICAL`
LOG_LEVEL=INFO
+# Log file path
+LOG_FILE=
+# Log file max size, the unit is MB
+LOG_FILE_MAX_SIZE=20
+# Log file max backup count
+LOG_FILE_BACKUP_COUNT=5
# Debug mode, default is false.
# It is recommended to turn on this configuration for local development
diff --git a/docker/docker-compose.yaml b/docker/docker-compose.yaml
index 75817949ab6..e4ad67892c8 100644
--- a/docker/docker-compose.yaml
+++ b/docker/docker-compose.yaml
@@ -1,6 +1,8 @@
x-shared-env: &shared-api-worker-env
LOG_LEVEL: ${LOG_LEVEL:-INFO}
LOG_FILE: ${LOG_FILE:-}
+ LOG_FILE_MAX_SIZE: ${LOG_FILE_MAX_SIZE:-20}
+ LOG_FILE_BACKUP_COUNT: ${LOG_FILE_BACKUP_COUNT:-5}
DEBUG: ${DEBUG:-false}
FLASK_DEBUG: ${FLASK_DEBUG:-false}
SECRET_KEY: ${SECRET_KEY:-sk-9f73s3ljTXVcMT3Blb3ljTqtsKiGHXVcMT3BlbkFJLK7U}