From cb7fcb7da90412fb62ded6c404106c072ede61e6 Mon Sep 17 00:00:00 2001 From: nannan00 <17491932+nannan00@users.noreply.github.com> Date: Wed, 14 Aug 2024 10:42:18 +0800 Subject: [PATCH 1/2] feat(settings): update log cfg --- saas/config/ce.py | 267 ++++++++++++++++++-------------------- saas/poetry.lock | 61 ++++++++- saas/pyproject.toml | 1 + saas/requirements.txt | 3 + saas/requirements_dev.txt | 3 + 5 files changed, 192 insertions(+), 143 deletions(-) diff --git a/saas/config/ce.py b/saas/config/ce.py index 8867eab3e..8bea14220 100644 --- a/saas/config/ce.py +++ b/saas/config/ce.py @@ -11,6 +11,8 @@ import os import random import string +from pathlib import Path +from typing import Any, Dict, List, Optional from urllib.parse import urlparse from . import RequestIDFilter @@ -207,160 +209,141 @@ STATIC_URL = env.str("BKPAAS_STATIC_URL", default=SITE_URL + "staticfiles/") AJAX_URL_PREFIX = SITE_URL + "api/v1" -# 只对正式环境日志级别进行配置,可以在这里修改 -LOG_LEVEL = env.str("BKAPP_LOG_LEVEL", default="ERROR") -_LOG_CLASS = "logging.handlers.RotatingFileHandler" -if IS_LOCAL: - LOG_LEVEL = "DEBUG" - _LOG_DIR = os.path.join(os.path.dirname(BASE_DIR), "logs", APP_CODE) - _LOG_NAME_PREFIX = env.str("BKPAAS_LOG_NAME_PREFIX", default=APP_CODE) - _LOGGING_FORMAT = { - "format": ( - "%(levelname)s [%(asctime)s] %(pathname)s " - "%(lineno)d %(funcName)s %(process)d %(thread)d " - "\n \t %(request_id)s\t%(message)s \n" - ), - "datefmt": "%Y-%m-%d %H:%M:%S", - } +# 日志等级,高于或等于该等级的日志才会被记录 +LOG_LEVEL = env.str("BKAPP_LOG_LEVEL", default=None) or env.str("LOG_LEVEL", default="ERROR") +# 用于存放日志文件的目录,默认值为空,表示不使用任何文件,所有日志直接输出到控制台。 +# 可配置为有效目录,支持相对或绝对地址,比如:"logs" 或 "/var/lib/app_logs/"。 +# 配置本选项后,原有的控制台日志输出将关闭。 +LOGGING_DIRECTORY = env.str("BKPAAS_APP_LOG_PATH", default=None) or env.str("LOGGING_DIRECTORY", default=None) +# 日志文件格式,可选值为:json/text +LOGGING_FILE_FORMAT = env.str("LOGGING_FILE_FORMAT", default="json") + +if LOGGING_DIRECTORY is None: + logging_to_console = True + logging_directory = None else: - _LOG_DIR = env.str("BKPAAS_APP_LOG_PATH", default="/") - _RAND_STR = "".join(random.sample(string.ascii_letters + string.digits, 4)) - _LOG_NAME_PREFIX = "%s-%s" % (env.str("BKPAAS_PROCESS_TYPE"), _RAND_STR) - - _LOGGING_FORMAT = { - "()": "pythonjsonlogger.jsonlogger.JsonFormatter", - "fmt": ( - "%(levelname)s %(asctime)s %(pathname)s %(lineno)d " - "%(funcName)s %(process)d %(thread)d %(request_id)s %(message)s" - ), - } -if not os.path.exists(_LOG_DIR): - os.makedirs(_LOG_DIR) -LOGGING = { - "version": 1, - "disable_existing_loggers": False, - "filters": { - "request_id_filter": { - "()": RequestIDFilter, - } - }, - "formatters": { - "verbose": _LOGGING_FORMAT, - "simple": {"format": "%(levelname)s %(message)s"}, - "bk_audit": {"format": "%(message)s"}, - }, - "handlers": { - "null": { - "level": "DEBUG", - "class": "logging.NullHandler", - }, - "console": {"level": "DEBUG", "class": "logging.StreamHandler", "formatter": "simple"}, - "root": { - "class": _LOG_CLASS, - "formatter": "verbose", - "filename": os.path.join(_LOG_DIR, "%s-django.log" % _LOG_NAME_PREFIX), - "maxBytes": 1024 * 1024 * 10, - "backupCount": 5, - "filters": ["request_id_filter"], - }, - "component": { - "class": _LOG_CLASS, - "formatter": "verbose", - "filename": os.path.join(_LOG_DIR, "%s-component.log" % _LOG_NAME_PREFIX), - "maxBytes": 1024 * 1024 * 10, - "backupCount": 5, - "filters": ["request_id_filter"], - }, - "mysql": { - "class": _LOG_CLASS, - "formatter": "verbose", - "filename": os.path.join(_LOG_DIR, "%s-mysql.log" % _LOG_NAME_PREFIX), - "maxBytes": 1024 * 1024 * 10, - "backupCount": 5, + logging_to_console = False + # The dir allows both absolute and relative path, when it's relative, combine + # the value with project's base directory + logging_directory = Path(BASE_DIR) / Path(LOGGING_DIRECTORY) + logging_directory.mkdir(exist_ok=True) + +# 是否总是打印日志到控制台,默认关闭 +logging_to_console = False +LOGGING_ALWAYS_CONSOLE = env.bool("LOGGING_ALWAYS_CONSOLE", default=False) +if LOGGING_ALWAYS_CONSOLE: + logging_to_console = True + + +def build_logging_config(log_level: str, to_console: bool, file_directory: Optional[Path], file_format: str) -> Dict: + """Build the global logging config dict. + + :param log_level: The log level. + :param to_console: If True, output the logs to the console. + :param file_directory: If the value is not None, output the logs to the given directory. + :param file_format: The format of the logging file, "json" or "text". + :return: The logging config dict. + """ + + def _build_file_handler(log_path: Path, filename: str, format: str) -> Dict: + if format not in ("json", "text"): + raise ValueError(f"Invalid file_format: {file_format}") + formatter = "verbose_json" if format == "json" else "verbose" + return { + "class": "concurrent_log_handler.ConcurrentRotatingFileHandler", + "level": log_level, + "formatter": formatter, "filters": ["request_id_filter"], - }, - "celery": { - "class": _LOG_CLASS, - "formatter": "verbose", - "filename": os.path.join(_LOG_DIR, "%s-celery.log" % _LOG_NAME_PREFIX), - "maxBytes": 1024 * 1024 * 10, + "filename": str(log_path / filename), + # Set max file size to 100MB + "maxBytes": 100 * 1024 * 1024, "backupCount": 5, - "filters": ["request_id_filter"], - }, - "organization": { - "class": _LOG_CLASS, + } + + handlers_config: Dict[str, Any] = { + "null": {"level": log_level, "class": "logging.NullHandler"}, + "console": { + "level": log_level, + "class": "logging.StreamHandler", "formatter": "verbose", - "filename": os.path.join(_LOG_DIR, "%s-json.log" % _LOG_NAME_PREFIX), - "maxBytes": 1024 * 1024 * 10, - "backupCount": 5, "filters": ["request_id_filter"], }, - "bk_audit": { - "class": _LOG_CLASS, + } + # 生成指定 Logger 对应的 Handlers + logger_handlers_map: Dict[str, List[str]] = {} + for logger_name in ["root", "component", "celery", "organization"]: + handlers = [] + + if to_console: + handlers.append("console") + + if file_directory: + # 生成 logger 对应日志文件的 Handler + handlers_config[logger_name] = _build_file_handler( + file_directory, f"{logger_name}-{file_format}.log", file_format + ) + handlers.append(logger_name) + + logger_handlers_map[logger_name] = handlers + + # bk_audit 特殊 Handler + handlers_config["bk_audit"] = {"level": log_level, "class": "logging.NullHandler"} + if file_directory: + handlers_config["bk_audit"] = { + "class": "concurrent_log_handler.ConcurrentRotatingFileHandler", + "level": log_level, "formatter": "bk_audit", - "filename": os.path.join(_LOG_DIR, "%s-audit.log" % _LOG_NAME_PREFIX), + "filename": str(file_directory / "audit.log"), "maxBytes": 1024 * 1024 * 10, "backupCount": 5, + } + + return { + "version": 1, + "disable_existing_loggers": False, + "filters": { + "request_id_filter": {"()": RequestIDFilter}, }, - }, - "loggers": { - "django": { - "handlers": ["null"], - "level": "INFO", - "propagate": True, - }, - "django.server": { - "handlers": ["console"], - "level": LOG_LEVEL, - "propagate": True, - }, - "django.request": { - "handlers": ["root"], - "level": "ERROR", - "propagate": True, - }, - "django.db.backends": { - "handlers": ["mysql"], - "level": LOG_LEVEL, - "propagate": True, - }, - # the root logger ,用于整个project的logger - "root": { - "handlers": ["root"], - "level": LOG_LEVEL, - "propagate": True, - }, - # 组件调用日志 - "component": { - "handlers": ["component"], - "level": LOG_LEVEL, - "propagate": True, - }, - "celery": { - "handlers": ["celery"], - "level": LOG_LEVEL, - "propagate": True, - }, - # 普通app日志 - "app": { - "handlers": ["root"], - "level": LOG_LEVEL, - "propagate": True, - }, - # 组织架构同步日志 - "organization": { - "handlers": ["root" if IS_LOCAL else "organization"], - "level": LOG_LEVEL, - "propagate": True, + "formatters": { + "verbose": { + "format": ( + "%(name)s %(levelname)s [%(asctime)s] %(pathname)s %(lineno)d %(funcName)s %(process)d %(thread)d " + "\n \t%(request_id)s\t%(message)s \n" + ), + "datefmt": "%Y-%m-%d %H:%M:%S", + }, + "verbose_json": { + "()": "pythonjsonlogger.jsonlogger.JsonFormatter", + "fmt": ( + "%(name)s %(levelname)s %(asctime)s %(pathname)s %(lineno)d " + "%(funcName)s %(process)d %(thread)d %(request_id)s %(message)s" + ), + }, + "simple": {"format": "%(name)s %(levelname)s %(message)s"}, + "bk_audit": {"format": "%(message)s"}, }, - # 审计日志文件 - "bk_audit": { - "handlers": ["bk_audit"], - "level": "INFO", - "propagate": True, + "handlers": handlers_config, + # the root logger, 用于整个项目的默认 logger + "root": {"handlers": logger_handlers_map["root"], "level": log_level, "propagate": False}, + "loggers": { + "django": {"handlers": ["null"], "level": "INFO", "propagate": True}, + "django.server": {"handlers": ["console"], "level": log_level, "propagate": False}, + "django.request": {"handlers": logger_handlers_map["root"], "level": log_level, "propagate": False}, + # 除 root 外的其他指定 Logger + **{ + logger_name: {"handlers": handlers, "level": log_level, "propagate": False} + for logger_name, handlers in logger_handlers_map.items() + if logger_name != "root" + }, + # 普通app日志 + "app": {"handlers": logger_handlers_map["root"], "level": LOG_LEVEL, "propagate": True}, + # 审计日志文件 + "bk_audit": {"handlers": ["bk_audit"], "level": "INFO", "propagate": True}, }, - }, -} + } + + +LOGGING = build_logging_config(LOG_LEVEL, logging_to_console, logging_directory, LOGGING_FILE_FORMAT) APP_API_URL = APP_URL # 前后端分离架构下, APP_URL 与 APP_API_URL 不一样 diff --git a/saas/poetry.lock b/saas/poetry.lock index a294a2c9f..8f666132a 100644 --- a/saas/poetry.lock +++ b/saas/poetry.lock @@ -416,6 +416,17 @@ category = "dev" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" +[[package]] +name = "concurrent-log-handler" +version = "0.9.25" +description = "RotatingFileHandler replacement with concurrency, gzip and Windows support" +category = "main" +optional = false +python-versions = ">=3.6" + +[package.dependencies] +portalocker = ">=1.6.0" + [[package]] name = "contextvars" version = "2.4" @@ -1451,6 +1462,22 @@ importlib-metadata = {version = ">=0.12", markers = "python_version < \"3.8\""} [package.extras] dev = ["pre-commit", "tox"] +[[package]] +name = "portalocker" +version = "2.7.0" +description = "Wraps the portalocker recipe for easy usage" +category = "main" +optional = false +python-versions = ">=3.5" + +[package.dependencies] +pywin32 = {version = ">=226", markers = "platform_system == \"Windows\""} + +[package.extras] +docs = ["sphinx (>=1.7.1)"] +redis = ["redis"] +tests = ["pytest (>=5.4.1)", "pytest-cov (>=2.8.1)", "pytest-mypy (>=0.8.0)", "pytest-timeout (>=2.1.0)", "redis", "sphinx (>=6.0.0)"] + [[package]] name = "prometheus-client" version = "0.13.0" @@ -1691,6 +1718,14 @@ category = "main" optional = false python-versions = "*" +[[package]] +name = "pywin32" +version = "306" +description = "Python for Window Extensions" +category = "main" +optional = false +python-versions = "*" + [[package]] name = "pyyaml" version = "5.4.1" @@ -2059,7 +2094,7 @@ testing = ["coverage (>=5.0.3)", "zope.event", "zope.testing"] [metadata] lock-version = "1.1" python-versions = "3.6.6" -content-hash = "c8a8f658bf82bde36e847d3f5ca4876471b7f5ca2bc752d94d2a1e6110a0512c" +content-hash = "c9800affbfce17977e6848f1613834fcd7b3fc4cb2feb60fa7114c263b3c4aee" [metadata.files] aenum = [ @@ -2225,6 +2260,10 @@ colorama = [ {file = "colorama-0.4.4-py2.py3-none-any.whl", hash = "sha256:9f47eda37229f68eee03b24b9748937c7dc3868f906e8ba69fbcbdd3bc5dc3e2"}, {file = "colorama-0.4.4.tar.gz", hash = "sha256:5941b2b48a20143d2267e95b1c2a7603ce057ee39fd88e7329b0c292aa16869b"}, ] +concurrent-log-handler = [ + {file = "concurrent_log_handler-0.9.25-py3-none-any.whl", hash = "sha256:157bee12914aa2a72246d1d0641ce07c1aa7a55faa3322bed02f21e60395eb82"}, + {file = "concurrent_log_handler-0.9.25.tar.gz", hash = "sha256:1e2c6f021414e214d3dac66107894827a3e78db63018304a4f29e55ba549ac22"}, +] contextvars = [ {file = "contextvars-2.4.tar.gz", hash = "sha256:f38c908aaa59c14335eeea12abea5f443646216c4e29380d7bf34d2018e2c39e"}, ] @@ -2869,6 +2908,10 @@ pluggy = [ {file = "pluggy-0.13.1-py2.py3-none-any.whl", hash = "sha256:966c145cd83c96502c3c3868f50408687b38434af77734af1e9ca461a4081d2d"}, {file = "pluggy-0.13.1.tar.gz", hash = "sha256:15b2acde666561e1298d71b523007ed7364de07029219b604cf808bfa1c765b0"}, ] +portalocker = [ + {file = "portalocker-2.7.0-py2.py3-none-any.whl", hash = "sha256:a07c5b4f3985c3cf4798369631fb7011adb498e2a46d8440efc75a8f29a0f983"}, + {file = "portalocker-2.7.0.tar.gz", hash = "sha256:032e81d534a88ec1736d03f780ba073f047a06c478b06e2937486f334e955c51"}, +] prometheus-client = [ {file = "prometheus_client-0.13.0-py3-none-any.whl", hash = "sha256:70782d19ea1a3aeb8523aa07780dbee6a595e566198ab4ed7fdc32b53b5fa1d1"}, {file = "prometheus_client-0.13.0.tar.gz", hash = "sha256:3fdc6fc5b03a9eaee44d015e2913b496864b9ad6557013f23e28f926d7b62913"}, @@ -3091,6 +3134,22 @@ pytz = [ {file = "pytz-2022.6-py2.py3-none-any.whl", hash = "sha256:222439474e9c98fced559f1709d89e6c9cbf8d79c794ff3eb9f8800064291427"}, {file = "pytz-2022.6.tar.gz", hash = "sha256:e89512406b793ca39f5971bc999cc538ce125c0e51c27941bef4568b460095e2"}, ] +pywin32 = [ + {file = "pywin32-306-cp310-cp310-win32.whl", hash = "sha256:06d3420a5155ba65f0b72f2699b5bacf3109f36acbe8923765c22938a69dfc8d"}, + {file = "pywin32-306-cp310-cp310-win_amd64.whl", hash = "sha256:84f4471dbca1887ea3803d8848a1616429ac94a4a8d05f4bc9c5dcfd42ca99c8"}, + {file = "pywin32-306-cp311-cp311-win32.whl", hash = "sha256:e65028133d15b64d2ed8f06dd9fbc268352478d4f9289e69c190ecd6818b6407"}, + {file = "pywin32-306-cp311-cp311-win_amd64.whl", hash = "sha256:a7639f51c184c0272e93f244eb24dafca9b1855707d94c192d4a0b4c01e1100e"}, + {file = "pywin32-306-cp311-cp311-win_arm64.whl", hash = "sha256:70dba0c913d19f942a2db25217d9a1b726c278f483a919f1abfed79c9cf64d3a"}, + {file = "pywin32-306-cp312-cp312-win32.whl", hash = "sha256:383229d515657f4e3ed1343da8be101000562bf514591ff383ae940cad65458b"}, + {file = "pywin32-306-cp312-cp312-win_amd64.whl", hash = "sha256:37257794c1ad39ee9be652da0462dc2e394c8159dfd913a8a4e8eb6fd346da0e"}, + {file = "pywin32-306-cp312-cp312-win_arm64.whl", hash = "sha256:5821ec52f6d321aa59e2db7e0a35b997de60c201943557d108af9d4ae1ec7040"}, + {file = "pywin32-306-cp37-cp37m-win32.whl", hash = "sha256:1c73ea9a0d2283d889001998059f5eaaba3b6238f767c9cf2833b13e6a685f65"}, + {file = "pywin32-306-cp37-cp37m-win_amd64.whl", hash = "sha256:72c5f621542d7bdd4fdb716227be0dd3f8565c11b280be6315b06ace35487d36"}, + {file = "pywin32-306-cp38-cp38-win32.whl", hash = "sha256:e4c092e2589b5cf0d365849e73e02c391c1349958c5ac3e9d5ccb9a28e017b3a"}, + {file = "pywin32-306-cp38-cp38-win_amd64.whl", hash = "sha256:e8ac1ae3601bee6ca9f7cb4b5363bf1c0badb935ef243c4733ff9a393b1690c0"}, + {file = "pywin32-306-cp39-cp39-win32.whl", hash = "sha256:e25fd5b485b55ac9c057f67d94bc203f3f6595078d1fb3b458c9c28b7153a802"}, + {file = "pywin32-306-cp39-cp39-win_amd64.whl", hash = "sha256:39b61c15272833b5c329a2989999dcae836b1eed650252ab1b7bfbe1d59f30f4"}, +] pyyaml = [ {file = "PyYAML-5.4.1-cp27-cp27m-macosx_10_9_x86_64.whl", hash = "sha256:3b2b1824fe7112845700f815ff6a489360226a5609b96ec2190a45e62a9fc922"}, {file = "PyYAML-5.4.1-cp27-cp27m-win32.whl", hash = "sha256:129def1b7c1bf22faffd67b8f3724645203b79d8f4cc81f674654d9902cb4393"}, diff --git a/saas/pyproject.toml b/saas/pyproject.toml index 7b6768b4a..0f47673ea 100644 --- a/saas/pyproject.toml +++ b/saas/pyproject.toml @@ -142,6 +142,7 @@ opentelemetry-semantic-conventions = "0.27b0" sqlparse = "0.4.4" urllib3 = "1.26.18" future = "0.18.3" +concurrent-log-handler = "0.9.25" [tool.poetry.dev-dependencies] # For flake8 support pyproject.toml diff --git a/saas/requirements.txt b/saas/requirements.txt index cdca4959d..7aa8e32e7 100644 --- a/saas/requirements.txt +++ b/saas/requirements.txt @@ -23,6 +23,7 @@ click-didyoumean==0.3.0; python_full_version >= "3.6.2" and python_full_version click-plugins==1.1.1; python_version >= "3.6" click-repl==0.2.0; python_version >= "3.6" click==7.1.2; python_full_version >= "3.6.2" and python_version >= "3.6" and python_version < "3.11" and python_full_version < "4.0.0" and (python_version >= "3.6" and python_full_version < "3.0.0" or python_full_version >= "3.5.0" and python_version >= "3.6") +concurrent-log-handler==0.9.25; python_version >= "3.6" contextvars==2.4; python_version < "3.7" and python_version >= "3.6" coreapi==2.3.3; python_version >= "3.6" coreschema==0.0.4; python_version >= "3.6" @@ -85,6 +86,7 @@ opentelemetry-sdk==1.8.0; python_version >= "3.6" opentelemetry-semantic-conventions==0.27b0; python_version >= "3.6" opentelemetry-util-http==0.27b0; python_version >= "3.6" packaging==21.0; python_full_version >= "3.6.1" and python_full_version < "4.0.0" and python_version >= "3.6" +portalocker==2.7.0; python_version >= "3.6" prometheus-client==0.13.0; python_version >= "3.6" prompt-toolkit==3.0.36; python_full_version >= "3.6.2" and python_version >= "3.6" protobuf==3.19.5; python_version >= "3.5" @@ -100,6 +102,7 @@ python-dateutil==2.8.2; python_version >= "2.7" and python_full_version < "3.0.0 python-editor==1.0.4; python_full_version >= "3.6.2" and python_version < "3.11" python-json-logger==0.1.7 pytz==2022.6 +pywin32==306; platform_system == "Windows" and python_version >= "3.6" pyyaml==5.4.1; python_full_version >= "3.6.1" and python_full_version < "4.0.0" redis==4.3.6; python_version >= "3.6" requests==2.27.1; (python_version >= "2.7" and python_full_version < "3.0.0") or (python_full_version >= "3.6.0") diff --git a/saas/requirements_dev.txt b/saas/requirements_dev.txt index c68066f91..ac5e39fae 100644 --- a/saas/requirements_dev.txt +++ b/saas/requirements_dev.txt @@ -29,6 +29,7 @@ click-plugins==1.1.1; python_version >= "3.6" click-repl==0.2.0; python_version >= "3.6" click==7.1.2; python_full_version >= "3.6.2" and python_version >= "3.6" and python_version < "3.11" and (python_version >= "3.6" and python_full_version < "3.0.0" or python_full_version >= "3.5.0" and python_version >= "3.6") and python_full_version < "4.0.0" colorama==0.4.4; python_version >= "3.6" and python_full_version < "3.0.0" and sys_platform == "win32" and platform_system == "Windows" or sys_platform == "win32" and python_version >= "3.6" and python_full_version >= "3.5.0" and platform_system == "Windows" +concurrent-log-handler==0.9.25; python_version >= "3.6" contextvars==2.4; python_version < "3.7" and python_version >= "3.6" converge==0.9.8 coreapi==2.3.3; python_version >= "3.6" @@ -109,6 +110,7 @@ packaging==21.0; python_full_version >= "3.6.1" and python_full_version < "4.0.0 pathspec==0.9.0; python_full_version >= "3.6.2" pbr==5.11.0; python_version >= "3.6" pluggy==0.13.1; python_version >= "3.6" and python_full_version < "3.0.0" or python_full_version >= "3.4.0" and python_version >= "3.6" +portalocker==2.7.0; python_version >= "3.6" prometheus-client==0.13.0; python_version >= "3.6" prompt-toolkit==3.0.36; python_full_version >= "3.6.2" and python_version >= "3.6" protobuf==3.19.5; python_version >= "3.5" @@ -131,6 +133,7 @@ python-dateutil==2.8.2; python_version >= "2.7" and python_full_version < "3.0.0 python-editor==1.0.4; python_full_version >= "3.6.2" and python_version < "3.11" python-json-logger==0.1.7 pytz==2022.6 +pywin32==306; platform_system == "Windows" and python_version >= "3.6" pyyaml==5.4.1; python_full_version >= "3.6.1" and python_full_version < "4.0.0" and (python_version >= "3.5" and python_full_version < "3.0.0" or python_full_version >= "3.6.0" and python_version >= "3.5") redis==4.3.6; python_version >= "3.6" regex==2021.8.3; python_full_version >= "3.6.2" From a4da7287a684c283a97409fd7f722bb08653edd0 Mon Sep 17 00:00:00 2001 From: nannan00 <17491932+nannan00@users.noreply.github.com> Date: Wed, 14 Aug 2024 10:47:28 +0800 Subject: [PATCH 2/2] fix: cr --- saas/config/ce.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/saas/config/ce.py b/saas/config/ce.py index 8bea14220..c0cf4df04 100644 --- a/saas/config/ce.py +++ b/saas/config/ce.py @@ -229,7 +229,6 @@ logging_directory.mkdir(exist_ok=True) # 是否总是打印日志到控制台,默认关闭 -logging_to_console = False LOGGING_ALWAYS_CONSOLE = env.bool("LOGGING_ALWAYS_CONSOLE", default=False) if LOGGING_ALWAYS_CONSOLE: logging_to_console = True @@ -287,11 +286,10 @@ def _build_file_handler(log_path: Path, filename: str, format: str) -> Dict: logger_handlers_map[logger_name] = handlers # bk_audit 特殊 Handler - handlers_config["bk_audit"] = {"level": log_level, "class": "logging.NullHandler"} + handlers_config["bk_audit"] = {"class": "logging.NullHandler"} if file_directory: handlers_config["bk_audit"] = { "class": "concurrent_log_handler.ConcurrentRotatingFileHandler", - "level": log_level, "formatter": "bk_audit", "filename": str(file_directory / "audit.log"), "maxBytes": 1024 * 1024 * 10,