diff --git a/docker/requirements.txt b/docker/requirements.txt index 4846f1832..47df1d07c 100644 --- a/docker/requirements.txt +++ b/docker/requirements.txt @@ -15,6 +15,7 @@ click==8.2.1 cobble==0.1.4 colorama==0.4.6 coloredlogs==15.0.1 +concurrent-log-handler==0.9.28 cryptography==45.0.5 cyclopts==3.22.2 defusedxml==0.7.1 diff --git a/poetry.lock b/poetry.lock index 926d580fb..a5890afb6 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 2.1.3 and should not be changed by hand. +# This file is automatically @generated by Poetry 2.1.4 and should not be changed by hand. [[package]] name = "absl-py" @@ -526,6 +526,24 @@ humanfriendly = ">=9.1" [package.extras] cron = ["capturer (>=2.4)"] +[[package]] +name = "concurrent-log-handler" +version = "0.9.28" +description = "RotatingFileHandler replacement with concurrency, gzip and Windows support. Size and time based rotation." +optional = false +python-versions = ">=3.6" +groups = ["main"] +files = [ + {file = "concurrent_log_handler-0.9.28-py3-none-any.whl", hash = "sha256:65db25d05506651a61573937880789fc51c7555e7452303042b5a402fd78939c"}, + {file = "concurrent_log_handler-0.9.28.tar.gz", hash = "sha256:4cc27969b3420239bd153779266f40d9713ece814e312b7aa753ce62c6eacdb8"}, +] + +[package.dependencies] +portalocker = ">=1.6.0" + +[package.extras] +dev = ["black", "coverage", "hatch", "pytest", "pytest-cov", "pytest-mock", "pytest-sugar", "ruff"] + [[package]] name = "contourpy" version = "1.3.2" @@ -3537,7 +3555,6 @@ files = [ {file = "portalocker-2.10.1-py3-none-any.whl", hash = "sha256:53a5984ebc86a025552264b459b46a2086e269b21823cb572f8f28ee759e45bf"}, {file = "portalocker-2.10.1.tar.gz", hash = "sha256:ef1bf844e878ab08aee7e40184156e1151f228f103aa5c6bd0724cc330960f8f"}, ] -markers = {main = "extra == \"all\""} [package.dependencies] pywin32 = {version = ">=226", markers = "platform_system == \"Windows\""} @@ -4053,7 +4070,7 @@ files = [ {file = "pywin32-311-cp39-cp39-win_amd64.whl", hash = "sha256:e0c4cfb0621281fe40387df582097fd796e80430597cb9944f0ae70447bacd91"}, {file = "pywin32-311-cp39-cp39-win_arm64.whl", hash = "sha256:62ea666235135fee79bb154e695f3ff67370afefd71bd7fea7512fc70ef31e3d"}, ] -markers = {main = "platform_system == \"Windows\" and extra == \"all\" or sys_platform == \"win32\"", eval = "platform_system == \"Windows\""} +markers = {main = "sys_platform == \"win32\" or platform_system == \"Windows\"", eval = "platform_system == \"Windows\""} [[package]] name = "pyyaml" @@ -6406,4 +6423,4 @@ tree-mem = ["neo4j", "schedule"] [metadata] lock-version = "2.1" python-versions = ">=3.10,<4.0" -content-hash = "ec17679a44205ada4494fbc485ac592883281fde273d5e73d6b8cbc6f7f9ed10" +content-hash = "8508256eeb2b554d4b50d4c4ec662a6f66a799d1b403953695db8cb3cf76f04a" diff --git a/pyproject.toml b/pyproject.toml index 29a29cca8..62ae503de 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -46,6 +46,7 @@ dependencies = [ "scikit-learn (>=1.7.0,<2.0.0)", # Machine learning "fastmcp (>=2.10.5,<3.0.0)", "python-dateutil (>=2.9.0.post0,<3.0.0)", + "concurrent-log-handler (>=0.9.28,<1.0.0)", # Process-safe rotating file handler ] [project.urls] diff --git a/src/memos/log.py b/src/memos/log.py index 874f2c6a7..9325a4861 100644 --- a/src/memos/log.py +++ b/src/memos/log.py @@ -53,6 +53,7 @@ def filter(self, record): record.user_name = get_current_user_name() record.api_path = get_current_api_path() except Exception: + record.api_path = "unknown" record.trace_id = "trace-id" record.env = "prod" record.user_type = "normal" @@ -196,7 +197,7 @@ def close(self): }, "file": { "level": "DEBUG", - "class": "logging.handlers.TimedRotatingFileHandler", + "class": "concurrent_log_handler.ConcurrentTimedRotatingFileHandler", "when": "midnight", "interval": 1, "backupCount": 3,